diff options
author | Tim Smith <tsmith84@gmail.com> | 2020-02-28 12:14:56 -0800 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2020-02-28 12:15:42 -0800 |
commit | f9987b12ce8b988251b651d10ec2a479756c3e2e (patch) | |
tree | 30e6b7b4ff513c5c3b0bf17bb31c7885ee776407 /spec | |
parent | 7b7d1556dfdcbec9b78334b89ec8fae35e709fc0 (diff) | |
download | chef-f9987b12ce8b988251b651d10ec2a479756c3e2e.tar.gz |
Remove all the code that checks for Windows Nanonano_support
Windows Nano isn't a thing anymore so we shouldn't spending compute time checking to see if we're on Windows Nano
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/powershell_script_spec.rb | 75 | ||||
-rw-r--r-- | spec/spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/platform_helpers.rb | 5 | ||||
-rw-r--r-- | spec/support/shared/functional/windows_script.rb | 17 | ||||
-rw-r--r-- | spec/unit/platform/query_helpers_spec.rb | 71 | ||||
-rw-r--r-- | spec/unit/provider/powershell_script_spec.rb | 94 | ||||
-rw-r--r-- | spec/unit/resource/powershell_script_spec.rb | 5 |
7 files changed, 47 insertions, 222 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index 74ece0d33c..32a128ac72 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -55,8 +55,6 @@ 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,7 +71,6 @@ 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. @@ -98,8 +95,6 @@ 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) @@ -118,34 +113,24 @@ 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) @@ -160,32 +145,24 @@ 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) @@ -204,8 +181,6 @@ 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) @@ -245,8 +220,6 @@ 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) @@ -318,7 +291,7 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do expect(source_contains_case_insensitive_content?( get_script_output, "AMD64" )).to eq(true) end - it "executes a script with a 32-bit process if :i386 arch is specified", :not_supported_on_nano do + it "executes a script with a 32-bit process if :i386 arch is specified" do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:i386) resource.returns(0) @@ -326,12 +299,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do expect(source_contains_case_insensitive_content?( get_script_output, "x86" )).to eq(true) end - - it "raises an error when executing a script with a 32-bit process on Windows Nano Server", :windows_nano_only do - resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") - expect { resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, - "cannot execute script with requested architecture 'i386' on Windows Nano Server") - end end describe "when executing guards" do @@ -385,8 +352,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -397,8 +362,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -419,8 +382,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -431,8 +392,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -443,8 +402,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -455,8 +412,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -467,8 +422,6 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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 @@ -511,36 +464,30 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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", :not_supported_on_nano do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean false as zero status code" 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", :not_supported_on_nano do + it "evaluates a 32-bit resource with a 32-bit guard and interprets boolean true as nonzero status code" 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 @@ -558,41 +505,33 @@ describe Chef::Resource::WindowsScript::PowershellScript, :windows_only do 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", :not_supported_on_nano 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" 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", :not_supported_on_nano 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" 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", :not_supported_on_nano 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" 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", :not_supported_on_nano 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" do resource.convert_boolean_return true resource.architecture :i386 resource.not_if "$env:PROCESSOR_ARCHITECTURE -eq 'X86'" expect(resource.should_skip?(:run)).to be_truthy end - - it "raises an error when a 32-bit guard is used on Windows Nano Server", :windows_nano_only do - resource.only_if "$true", architecture: :i386 - expect { resource.run_action(:run) }.to raise_error( - Chef::Exceptions::Win32ArchitectureIncorrect, - /cannot execute script with requested architecture 'i386' on Windows Nano Server/ - ) - end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3154e2f255..36ad0e5c48 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -153,11 +153,9 @@ RSpec.configure do |config| config.filter_run_excluding not_supported_on_aix: true if aix? config.filter_run_excluding not_supported_on_solaris: true if solaris? config.filter_run_excluding not_supported_on_gce: true if gce? - config.filter_run_excluding not_supported_on_nano: true if windows_nano_server? config.filter_run_excluding win2012r2_only: true unless windows_2012r2? config.filter_run_excluding windows64_only: true unless windows64? config.filter_run_excluding windows32_only: true unless windows32? - config.filter_run_excluding windows_nano_only: true unless windows_nano_server? config.filter_run_excluding windows_gte_10: true unless windows_gte_10? config.filter_run_excluding windows_lt_10: true if windows_gte_10? config.filter_run_excluding ruby64_only: true unless ruby_64bit? diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb index c92b3dca39..f9d8955f1e 100644 --- a/spec/support/platform_helpers.rb +++ b/spec/support/platform_helpers.rb @@ -88,11 +88,6 @@ def windows_powershell_dsc? supports_dsc end -def windows_nano_server? - require "chef/platform/query_helpers" - Chef::Platform.windows_nano_server? -end - def windows_user_right?(right) return false unless windows? diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index 49fd727055..eca63a6af3 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -99,7 +99,7 @@ shared_context Chef::Resource::WindowsScript do end end - context "when the guard's architecture is specified as 32-bit", :not_supported_on_nano do + context "when the guard's architecture is specified as 32-bit" do let (:guard_architecture) { :i386 } it "executes a 32-bit guard" do resource.only_if resource_guard_command, architecture: guard_architecture @@ -107,17 +107,6 @@ shared_context Chef::Resource::WindowsScript do expect(get_guard_process_architecture).to eq("x86") end end - - context "when the guard's architecture is specified as 32-bit", :windows_nano_only do - let (:guard_architecture) { :i386 } - it "raises an error" do - resource.only_if resource_guard_command, architecture: guard_architecture - expect { resource.run_action(:run) }.to raise_error( - Chef::Exceptions::Win32ArchitectureIncorrect, - /cannot execute script with requested architecture 'i386' on Windows Nano Server/ - ) - end - end end end @@ -218,8 +207,6 @@ shared_context Chef::Resource::WindowsScript do context "when evaluating guards" do it "has a guard_interpreter attribute set to the short name of the resource" do - pending "powershell.exe always exits with 0 on nano" if Chef::Platform.windows_nano_server? - expect(resource.guard_interpreter).to eq(resource.resource_name) resource.not_if "findstr.exe /thiscommandhasnonzeroexitstatus" expect(Chef::Resource).to receive(:resource_for_node).and_call_original @@ -238,7 +225,7 @@ shared_context Chef::Resource::WindowsScript do it_behaves_like "a script resource with architecture attribute" end - context "when the architecture attribute is :i386", :not_supported_on_nano do + context "when the architecture attribute is :i386" do let(:resource_architecture) { :i386 } it_behaves_like "a script resource with architecture attribute" end diff --git a/spec/unit/platform/query_helpers_spec.rb b/spec/unit/platform/query_helpers_spec.rb index d5e4d09029..55e2b4b44c 100644 --- a/spec/unit/platform/query_helpers_spec.rb +++ b/spec/unit/platform/query_helpers_spec.rb @@ -18,77 +18,6 @@ require "spec_helper" -describe "Chef::Platform#windows_nano_server?" do - include_context "Win32" - - let(:key) { "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Server\\ServerLevels" } - let(:key_query_value) { 0x0001 } - let(:access) { key_query_value | 0x0100 } - let(:hive) { double("Win32::Registry::HKEY_LOCAL_MACHINE") } - let(:registry) { double("Win32::Registry") } - - before(:all) do - Win32::Registry = Class.new - Win32::Registry::Error = Class.new(RuntimeError) - end - - before do - Win32::Registry::HKEY_LOCAL_MACHINE = hive - Win32::Registry::KEY_QUERY_VALUE = key_query_value - end - - after do - Win32::Registry.send(:remove_const, "HKEY_LOCAL_MACHINE") if defined?(Win32::Registry::HKEY_LOCAL_MACHINE) - Win32::Registry.send(:remove_const, "KEY_QUERY_VALUE") if defined?(Win32::Registry::KEY_QUERY_VALUE) - end - - it "returns false early when not on windows" do - allow(ChefUtils).to receive(:windows?).and_return(false) - expect(Chef::Platform).to_not receive(:require) - expect(Chef::Platform.windows_nano_server?).to be false - end - - it "returns true when the registry value is 1" do - allow(ChefUtils).to receive(:windows?).and_return(true) - allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) - .with(key, access) - .and_yield(registry) - expect(registry).to receive(:[]).with("NanoServer").and_return(1) - expect(Chef::Platform.windows_nano_server?).to be true - end - - it "returns false when the registry value is not 1" do - allow(ChefUtils).to receive(:windows?).and_return(true) - allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) - .with(key, access) - .and_yield(registry) - expect(registry).to receive(:[]).with("NanoServer").and_return(0) - expect(Chef::Platform.windows_nano_server?).to be false - end - - it "returns false when the registry value does not exist" do - allow(ChefUtils).to receive(:windows?).and_return(true) - allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) - .with(key, access) - .and_yield(registry) - expect(registry).to receive(:[]).with("NanoServer") - .and_raise(Win32::Registry::Error, "The system cannot find the file specified.") - expect(Chef::Platform.windows_nano_server?).to be false - end - - it "returns false when the registry key does not exist" do - allow(ChefUtils).to receive(:windows?).and_return(true) - allow(Chef::Platform).to receive(:require).with("win32/registry") - expect(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open) - .with(key, access) - .and_raise(Win32::Registry::Error, "The system cannot find the file specified.") - expect(Chef::Platform.windows_nano_server?).to be false - end -end - describe "Chef::Platform#supports_msi?" do include_context "Win32" # clear and restore Win32:: namespace diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb index cca0f34067..0bb0bf701b 100644 --- a/spec/unit/provider/powershell_script_spec.rb +++ b/spec/unit/provider/powershell_script_spec.rb @@ -53,73 +53,55 @@ describe Chef::Provider::PowershellScript, "action_run" do end context "when setting interpreter flags" do - context "on nano" do - before(:each) do - allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true) - allow(provider).to receive(:is_forced_32bit).and_return(false) - os_info_double = double("os_info") - allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double) - allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32") - end - - it "sets the -Command flag as the last flag" do - flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ } - expect(flags.pop).to eq("-Command") - end + before(:each) do + allow(provider).to receive(:is_forced_32bit).and_return(false) + os_info_double = double("os_info") + allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double) + allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32") end - context "not on nano" do - before(:each) do - allow(Chef::Platform).to receive(:windows_nano_server?).and_return(false) - allow(provider).to receive(:is_forced_32bit).and_return(false) - os_info_double = double("os_info") - allow(provider.run_context.node["kernel"]).to receive(:[]).with("os_info").and_return(os_info_double) - allow(os_info_double).to receive(:[]).with("system_directory").and_return("C:\\Windows\\system32") - end + it "sets the -File flag as the last flag" do + flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ } + expect(flags.pop).to eq("-File") + end - it "sets the -File flag as the last flag" do - flags = provider.command.split(" ").keep_if { |flag| flag =~ /^-/ } - expect(flags.pop).to eq("-File") - end + let(:execution_policy_flag) do + provider_flags = provider.flags.split(" ") + # Last occurance of "executionpolicy" + execution_policy_index = provider_flags.map(&:downcase).rindex("-executionpolicy") - let(:execution_policy_flag) do - provider_flags = provider.flags.split(" ") - # Last occurance of "executionpolicy" - execution_policy_index = provider_flags.map(&:downcase).rindex("-executionpolicy") + execution_policy_index ? provider_flags[execution_policy_index + 1] : nil + end - execution_policy_index ? provider_flags[execution_policy_index + 1] : nil + context "when running with an unspecified PowerShell version" do + let(:powershell_version) { nil } + it "sets default -ExecutionPolicy flag to 'Unrestricted'" do + expect(execution_policy_flag.downcase).to eq("unrestricted".downcase) end - - context "when running with an unspecified PowerShell version" do - let(:powershell_version) { nil } - it "sets default -ExecutionPolicy flag to 'Unrestricted'" do - expect(execution_policy_flag.downcase).to eq("unrestricted".downcase) - end - it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do - set_user_defined_flag - expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) - end + it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do + set_user_defined_flag + expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) end + end - { "2.0" => "Unrestricted", - "2.5" => "Unrestricted", - "3.0" => "Bypass", - "3.6" => "Bypass", - "4.0" => "Bypass", - "5.0" => "Bypass" }.each do |version_policy| + { "2.0" => "Unrestricted", + "2.5" => "Unrestricted", + "3.0" => "Bypass", + "3.6" => "Bypass", + "4.0" => "Bypass", + "5.0" => "Bypass" }.each do |version_policy| + let(:powershell_version) { version_policy[0].to_f } + context "when running PowerShell version #{version_policy[0]}" do let(:powershell_version) { version_policy[0].to_f } - context "when running PowerShell version #{version_policy[0]}" do - let(:powershell_version) { version_policy[0].to_f } - it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do - expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase) - end - it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do - set_user_defined_flag - expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) - end + it "sets default -ExecutionPolicy flag to '#{version_policy[1]}'" do + expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase) + end + it "sets user defined -ExecutionPolicy flag to 'RemoteSigned'" do + set_user_defined_flag + expect(execution_policy_flag.downcase).to eq("RemoteSigned".downcase) end end - end + end end end diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index 5566f32725..ce6b8ecea4 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -47,11 +47,6 @@ describe Chef::Resource::PowershellScript do expect(@resource.convert_boolean_return).to eq(false) end - it "raises an error when architecture is i386 on Windows Nano Server" do - allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true) - expect { @resource.architecture(:i386) }.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture 'i386' on Windows Nano Server") - end - context "when using guards" do let(:resource) { @resource } before(:each) do |