Skip to content

Commit

Permalink
Merge pull request #227 from chef/tests
Browse files Browse the repository at this point in the history
fix broken windows tests
  • Loading branch information
Lamont Granquist authored Jan 25, 2021
2 parents 131ae2f + 57968d6 commit 9581c70
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ steps:
executor:
docker:
host_os: windows
user: 'NT AUTHORITY\SYSTEM'
19 changes: 10 additions & 9 deletions spec/mixlib/shellout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,12 @@
# to match how whoami returns the information

it "should run as current user" do
expect(running_user).to eql("#{ENV["USERDOMAIN"].downcase}\\#{ENV["USERNAME"].downcase}")
if ENV["USERNAME"] == "#{ENV["COMPUTERNAME"]}$"
expected_user = "nt authority\\system"
else
expected_user = "#{ENV["USERDOMAIN"].downcase}\\#{ENV["USERNAME"].downcase}"
end
expect(running_user).to eql(expected_user)
end
end

Expand Down Expand Up @@ -787,16 +792,12 @@
end

context "when not using a batch file" do
let(:cmd) { "#{executable_file_name} #{script_name}" }

let(:executable_file_name) { "\"#{dir}/Ruby Parser.exe\"".tap(&make_executable!) }
let(:make_executable!) { lambda { |filename| Mixlib::ShellOut.new("copy \"#{full_path_to_ruby}\" #{filename}").run_command } }
let(:script_content) { "print \"#{expected_output}\"" }
let(:cmd) { "#{executable_file_name} -command #{script_content}" }
let(:executable_file_name) { "\"#{dir}/Powershell Parser.exe\"".tap(&make_executable!) }
let(:make_executable!) { lambda { |filename| Mixlib::ShellOut.new("copy \"c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe\" #{filename}").run_command } }
let(:script_content) { "Write-Host \"#{expected_output}\"" }
let(:expected_output) { "Random #{rand(10000)}" }

let(:full_path_to_ruby) { ENV["PATH"].split(";").map(&try_ruby).reject(&:nil?).first }
let(:try_ruby) { lambda { |path| "#{path}\\ruby.exe" if File.executable? "#{path}\\ruby.exe" } }

it "should execute" do
is_expected.to eql(expected_output)
end
Expand Down

0 comments on commit 9581c70

Please sign in to comment.