diff options
author | Claire McQuin <mcquin@users.noreply.github.com> | 2015-10-02 15:14:06 -0700 |
---|---|---|
committer | Claire McQuin <mcquin@users.noreply.github.com> | 2015-10-02 15:14:06 -0700 |
commit | 69cf21c8b35d7fb94775db377e810908e5fad54a (patch) | |
tree | c1b1df8585f8bf881c4ca4beaad0e118145298a6 /spec/functional | |
parent | 86a62b1d54c28bf5855c76b6404452fc6ebae43c (diff) | |
parent | e444aeb53a2e031b4c8e6300b380fe26c14e203c (diff) | |
download | chef-69cf21c8b35d7fb94775db377e810908e5fad54a.tar.gz |
Merge pull request #4016 from chef/mcquin/nano-ps-script
Use -Command flag on Nano
Diffstat (limited to 'spec/functional')
-rw-r--r-- | spec/functional/resource/powershell_script_spec.rb | 64 |
1 files changed, 57 insertions, 7 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index be744e748b..ba0f867fcc 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -16,6 +16,7 @@ # limitations under the License. # +require 'chef/platform/query_helpers' require 'spec_helper' describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do @@ -27,7 +28,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do it_behaves_like "a Windows script running on Windows" - let(:successful_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe $env:systemroot" } let(:failed_executable_script_content) { "#{ENV['SystemRoot']}\\system32\\attrib.exe /badargument" } let(:processor_architecture_script_content) { "echo $env:PROCESSOR_ARCHITECTURE" } @@ -57,6 +57,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns the exit status 27 for a powershell script that exits with 27" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + file = Tempfile.new(['foo', '.ps1']) begin file.write "exit 27" @@ -73,6 +75,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do let (:negative_exit_status) { -27 } let (:unsigned_exit_status) { (-negative_exit_status ^ 65535) + 1 } it "returns the exit status -27 as a signed integer or an unsigned 16-bit 2's complement value of 65509 for a powershell script that exits with -27" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + # Versions of PowerShell prior to 4.0 return a 16-bit unsigned value -- # PowerShell 4.0 and later versions return a 32-bit signed value. file = Tempfile.new(['foo', '.ps1']) @@ -96,6 +100,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns the process exit code" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code(arbitrary_nonzero_process_exit_code_content) resource.returns(arbitrary_nonzero_process_exit_code) resource.run_action(:run) @@ -114,24 +120,34 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns 1 if the last command was a cmdlet that failed" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code(cmdlet_exit_code_not_found_content) resource.returns(1) resource.run_action(:run) end it "returns 1 if the last command was a cmdlet that failed and was preceded by a successfully executed non-cmdlet Windows binary" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code([windows_process_exit_code_success_content, cmdlet_exit_code_not_found_content].join(';')) resource.returns(1) expect { resource.run_action(:run) }.not_to raise_error end it "raises a Mixlib::ShellOut::ShellCommandFailed error if the script is not syntactically correct" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code('if({)') resource.returns(0) expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) end it "raises an error if the script is not syntactically correct even if returns is set to 1 which is what powershell.exe returns for syntactically invalid scripts" do + # This test fails because shell_out expects the exit status to be 1, but it is actually 0 + # The error is a false-positive. + skip "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code('if({)') resource.returns(1) expect { resource.run_action(:run) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed) @@ -146,24 +162,32 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do # errors than 0 or 1, we return that instead, which is acceptable # since callers can test for nonzero rather than testing for 1. it "returns 1 if the last command was a cmdlet that failed and was preceded by an unsuccessfully executed non-cmdlet Windows binary" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code([arbitrary_nonzero_process_exit_code_content,cmdlet_exit_code_not_found_content].join(';')) resource.returns(arbitrary_nonzero_process_exit_code) resource.run_action(:run) end it "returns 0 if the last command was a non-cmdlet Windows binary that succeeded and was preceded by a failed cmdlet" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(';')) resource.returns(arbitrary_nonzero_process_exit_code) resource.run_action(:run) end it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that succeeded" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code([cmdlet_exit_code_success_content, arbitrary_nonzero_process_exit_code_content].join(';')) resource.returns(arbitrary_nonzero_process_exit_code) resource.run_action(:run) end it "returns a specific error code if the last command was a non-cmdlet Windows binary that failed and was preceded by cmdlet that failed" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code([cmdlet_exit_code_not_found_content, arbitrary_nonzero_process_exit_code_content].join(';')) resource.returns(arbitrary_nonzero_process_exit_code) resource.run_action(:run) @@ -182,6 +206,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns 1 for $false as the last line of the script when convert_boolean_return is true" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.convert_boolean_return true resource.code "$false" resource.returns(1) @@ -208,6 +234,8 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do end it "returns 1 if an invalid flag is passed to the interpreter" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.code(cmdlet_exit_code_success_content) resource.flags(invalid_powershell_interpreter_flag) resource.returns(1) @@ -287,6 +315,8 @@ configuration LCM end it "executes a script with a 32-bit process if :i386 arch is specified" do + pending "executing scripts with a 32-bit process should raise an error on nano" if Chef::Platform.windows_nano_server? + resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:i386) resource.returns(0) @@ -347,6 +377,8 @@ configuration LCM end it "evaluates a powershell $false for a not_if block as true" do + pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server? + resource.not_if "$false" expect(resource.should_skip?(:run)).to be_falsey end @@ -357,6 +389,8 @@ configuration LCM end it "evaluates a powershell $false for an only_if block as false" do + pending "powershell.exe always exits with $true on nano" if Chef::Platform.windows_nano_server? + resource.only_if "$false" expect(resource.should_skip?(:run)).to be_truthy end @@ -377,6 +411,8 @@ configuration LCM end it "evaluates a non-zero powershell exit status for not_if as true" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.not_if "exit 37" expect(resource.should_skip?(:run)).to be_falsey end @@ -387,6 +423,8 @@ configuration LCM end it "evaluates a failed executable exit status for not_if as false" do + pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server? + resource.not_if windows_process_exit_code_not_found_content expect(resource.should_skip?(:run)).to be_falsey end @@ -397,6 +435,8 @@ configuration LCM end it "evaluates a failed executable exit status for only_if as false" do + pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server? + resource.only_if windows_process_exit_code_not_found_content expect(resource.should_skip?(:run)).to be_truthy end @@ -407,6 +447,8 @@ configuration LCM end it "evaluates a failed cmdlet exit status for not_if as true" do + pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server? + resource.not_if "throw 'up'" expect(resource.should_skip?(:run)).to be_falsey end @@ -417,6 +459,8 @@ configuration LCM end it "evaluates a failed cmdlet exit status for only_if as false" do + pending "powershell.exe always exits with success on nano" if Chef::Platform.windows_nano_server? + resource.only_if "throw 'up'" expect(resource.should_skip?(:run)).to be_truthy end @@ -459,30 +503,36 @@ configuration LCM end it "evaluates a 64-bit resource with a 64-bit guard and interprets boolean true as nonzero status code", :windows64_only do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.architecture :x86_64 resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'AMD64')" expect(resource.should_skip?(:run)).to be_truthy end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code", :not_supported_on_nano do resource.architecture :i386 resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -ne 'X86')" expect(resource.should_skip?(:run)).to be_falsey end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code", :not_supported_on_nano do resource.architecture :i386 resource.only_if "exit [int32]($env:PROCESSOR_ARCHITECTURE -eq 'X86')" expect(resource.should_skip?(:run)).to be_truthy end it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for only_if" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.convert_boolean_return true resource.only_if "$false" expect(resource.should_skip?(:run)).to be_truthy end it "evaluates a simple boolean false as nonzero status code when convert_boolean_return is true for not_if" do + pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? + resource.convert_boolean_return true resource.not_if "$false" expect(resource.should_skip?(:run)).to be_falsey @@ -500,28 +550,28 @@ configuration LCM expect(resource.should_skip?(:run)).to be_truthy end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for only_if", :not_supported_on_nano do resource.convert_boolean_return true resource.architecture :i386 resource.only_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'" expect(resource.should_skip?(:run)).to be_falsey end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code using convert_boolean_return for not_if", :not_supported_on_nano do resource.convert_boolean_return true resource.architecture :i386 resource.not_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'" expect(resource.should_skip?(:run)).to be_falsey end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for only_if", :not_supported_on_nano do resource.convert_boolean_return true resource.architecture :i386 resource.only_if "$env:PROCESSOR_ARCHITECTURE -ne 'X86'" expect(resource.should_skip?(:run)).to be_truthy end - it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if" do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code using convert_boolean_return for not_if", :not_supported_on_nano do resource.convert_boolean_return true resource.architecture :i386 resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'" |