Skip to content

Commit

Permalink
(maint) Fixed mkdir_p problems found in voxpopuli module
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-miclea committed May 20, 2020
1 parent 8f17817 commit 9288623
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/beaker/host/unix/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_ip
# @param [String] 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}\""
cmd = "mkdir -p #{dir}"
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
result.exit_code == 0
end
Expand All @@ -150,7 +150,7 @@ def rm_rf path
# @param [Boolean] rm Remove the destination prior to move
def mv orig, dest, rm=true
rm_rf dest unless !rm
execute("mv \"#{orig}\" \"#{dest}\"")
execute("mv #{orig} #{dest}")
end

# Attempt to ping the provided target hostname
Expand Down
19 changes: 19 additions & 0 deletions lib/beaker/host/windows/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ def selinux_enabled?()
false
end

# Create the provided directory structure on the host
# @param [String] 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}\""
result = exec(Beaker::Command.new(cmd), :acceptable_exit_codes => [0, 1])
result.exit_code == 0
end

# Move the origin to destination. The destination is removed prior to moving.
# @param [String] orig The origin path
# @param [String] dest the destination path
# @param [Boolean] rm Remove the destination prior to move
def mv orig, dest, rm=true
rm_rf dest unless !rm
execute("mv \"#{orig}\" \"#{dest}\"")
end


# Determine if cygwin is actually installed on the SUT. Differs from
# is_cygwin?, which is just a type check for a Windows::Host.
#
Expand Down
4 changes: 2 additions & 2 deletions spec/beaker/host/unix/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ def to_s

it 'rm first' do
expect( instance ).to receive(:execute).with("rm -rf #{destination}").and_return(0)
expect( instance ).to receive(:execute).with("mv \"#{origin}\" \"#{destination}\"").and_return(0)
expect( instance ).to receive(:execute).with("mv #{origin} #{destination}").and_return(0)
expect( instance.mv(origin, destination) ).to be === 0

end

it 'does not rm' do
expect( instance ).to receive(:execute).with("mv \"#{origin}\" \"#{destination}\"").and_return(0)
expect( instance ).to receive(:execute).with("mv #{origin} #{destination}").and_return(0)
expect( instance.mv(origin, destination, false) ).to be === 0
end
end
Expand Down
18 changes: 18 additions & 0 deletions spec/beaker/host/windows/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Beaker
describe Windows::Exec do
class WindowsExecTest
include Unix::Exec
include Windows::Exec

def initialize(hash, logger)
Expand Down Expand Up @@ -78,5 +79,22 @@ def to_s
expect(instance.cygwin_installed?).to eq(false)
end
end

context 'mv' do
let(:origin) { '/origin/path/of/content' }
let(:destination) { '/destination/path/of/content' }

it 'rm first' do
expect( instance ).to receive(:execute).with("rm -rf #{destination}").and_return(0)
expect( instance ).to receive(:execute).with("mv \"#{origin}\" \"#{destination}\"").and_return(0)
expect( instance.mv(origin, destination) ).to be === 0

end

it 'does not rm' do
expect( instance ).to receive(:execute).with("mv \"#{origin}\" \"#{destination}\"").and_return(0)
expect( instance.mv(origin, destination, false) ).to be === 0
end
end
end
end

0 comments on commit 9288623

Please sign in to comment.