Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create ~/.ssh on Windows if it doesn't exist #1745

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/beaker/host/windows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ def selinux_enabled?()
end

# Create the provided directory structure on the host
# @param [String] dir The directory structure to create on the host
# @param [String,Pathname] dir The directory structure to create on the host
# @return [Boolean] True, if directory construction succeeded, otherwise False
def mkdir_p dir
cmd = "mkdir -p \"#{dir}\""
def mkdir_p(dir)
# single or double quotes will disable ~ expansion, so only quote if we have to
str = dir.to_s
cmd = if str.start_with?('~') && !str.include?(' ')
"mkdir -p #{str}"
else
"mkdir -p \"#{str}\""
end
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
result.exit_code == 0
end
Expand Down
30 changes: 30 additions & 0 deletions spec/beaker/host/windows/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,35 @@ def to_s
expect( instance.mv(origin, destination, false) ).to be === 0
end
end

context 'mkdir_p' do
let(:path) { '~/.ssh' }
let(:result) do
result = Beaker::Result.new(nil, '')
result.exit_code = 0
result
end

it 'accepts Pathname arguments' do
expect( instance ).to receive(:exec).with(having_attributes(command: "mkdir -p #{path}"), anything).and_return(result)
expect(instance.mkdir_p(Pathname.new(path))).to eq(true)
end

it 'omits quotes if the path starts with ~ and does not contain spaces' do
expect( instance ).to receive(:exec).with(having_attributes(command: "mkdir -p #{path}"), anything).and_return(result)
expect(instance.mkdir_p(path)).to eq(true)
end

it 'double quotes paths containing spaces' do
expect( instance ).to receive(:exec).with(having_attributes(command: "mkdir -p \"~/.foo bar\""), anything).and_return(result)
expect(instance.mkdir_p("~/.foo bar")).to eq(true)
end

it 'returns false if the command failed' do
result.exit_code = 1
expect( instance ).to receive(:exec).with(having_attributes(command: "mkdir -p #{path}"), anything).and_return(result)
expect(instance.mkdir_p(path)).to eq(false)
end
end
end
end