diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/functional/resource/powershell_script_spec.rb | 17 | ||||
-rw-r--r-- | spec/functional/resource/user/windows_spec.rb | 8 | ||||
-rw-r--r-- | spec/integration/recipes/resource_action_spec.rb | 5 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/shared/functional/windows_script.rb | 37 | ||||
-rw-r--r-- | spec/unit/application/client_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/application/knife_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/event_dispatch/dispatcher_spec.rb | 47 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/powershell_script_spec.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/user/windows_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/powershell_script_spec.rb | 30 | ||||
-rw-r--r-- | spec/unit/run_list/versioned_recipe_list_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/search/query_spec.rb | 20 |
15 files changed, 175 insertions, 32 deletions
diff --git a/spec/functional/resource/powershell_script_spec.rb b/spec/functional/resource/powershell_script_spec.rb index ba0f867fcc..91b74fd752 100644 --- a/spec/functional/resource/powershell_script_spec.rb +++ b/spec/functional/resource/powershell_script_spec.rb @@ -314,9 +314,7 @@ configuration LCM 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" do - pending "executing scripts with a 32-bit process should raise an error on nano" if Chef::Platform.windows_nano_server? - + it "executes a script with a 32-bit process if :i386 arch is specified", :not_supported_on_nano do resource.code(processor_architecture_script_content + " | out-file -encoding ASCII #{script_output_path}") resource.architecture(:i386) resource.returns(0) @@ -324,6 +322,12 @@ configuration LCM 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 @@ -577,6 +581,13 @@ configuration LCM 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/functional/resource/user/windows_spec.rb b/spec/functional/resource/user/windows_spec.rb index 5e68478b34..5e3a9090d4 100644 --- a/spec/functional/resource/user/windows_spec.rb +++ b/spec/functional/resource/user/windows_spec.rb @@ -66,6 +66,14 @@ describe Chef::Provider::User::Windows, :windows_only do new_resource.run_action(:create) expect(new_resource).to be_updated_by_last_action end + + context 'with a gid specified' do + it 'warns unsupported' do + expect(Chef::Log).to receive(:warn).with(/not implemented/) + new_resource.gid('agroup') + new_resource.run_action(:create) + end + end end describe 'action :remove' do diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb index 1c84b986cc..6f3f5ab47e 100644 --- a/spec/integration/recipes/resource_action_spec.rb +++ b/spec/integration/recipes/resource_action_spec.rb @@ -202,6 +202,11 @@ describe "Resource.action" do let(:resource_dsl) { :action_jackson } end + it "Can retrieve ancestors of action class without crashing" do + converge { action_jackson 'hi' } + expect { ActionJackson.action_class.ancestors.join(",") }.not_to raise_error + end + context "And 'action_jackgrandson' inheriting from ActionJackson and changing nothing" do before(:context) { class ActionJackgrandson < ActionJackson diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3a1d116d79..4f7fde8eaf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -133,6 +133,7 @@ RSpec.configure do |config| config.filter_run_excluding :windows_2008r2_or_later => true unless windows_2008r2_or_later? 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 :ruby64_only => true unless ruby_64bit? config.filter_run_excluding :ruby32_only => true unless ruby_32bit? config.filter_run_excluding :windows_powershell_dsc_only => true unless windows_powershell_dsc? diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index b6fc2a98ad..d84c06c86b 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -103,16 +103,24 @@ shared_context Chef::Resource::WindowsScript do end end - context "when the guard's architecture is specified as 32-bit" do + context "when the guard's architecture is specified as 32-bit", :not_supported_on_nano do let (:guard_architecture) { :i386 } it "executes a 32-bit guard" do - pending "executing scripts with a 32-bit process should raise an error on nano" if Chef::Platform.windows_nano_server? - resource.only_if resource_guard_command, :architecture => guard_architecture resource.run_action(:run) 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 @@ -120,7 +128,28 @@ shared_context Chef::Resource::WindowsScript do describe "when the run action is invoked on Windows" do it "executes the script code" do - resource.code("whoami > #{script_output_path}") + resource.code("whoami > \"#{script_output_path}\"") + resource.returns(0) + resource.run_action(:run) + end + end + + context "when $env:TMP has a space" do + before(:each) do + @dir = Dir.mktmpdir("Jerry Smith") + @original_env = ENV.to_hash.dup + ENV.delete('TMP') + ENV['TMP'] = @dir + end + + after(:each) do + FileUtils.remove_entry_secure(@dir) + ENV.clear + ENV.update(@original_env) + end + + it "executes the script code" do + resource.code("whoami > \"#{script_output_path}\"") resource.returns(0) resource.run_action(:run) end diff --git a/spec/unit/application/client_spec.rb b/spec/unit/application/client_spec.rb index 831a3fc19e..727536f1f8 100644 --- a/spec/unit/application/client_spec.rb +++ b/spec/unit/application/client_spec.rb @@ -288,9 +288,9 @@ describe Chef::Application::Client, "configure_chef" do ARGV.replace(@original_argv) end - it "should set the colored output to false by default on windows and true otherwise" do + it "should set the colored output to true by default on windows and true on all other platforms as well" do if windows? - expect(Chef::Config[:color]).to be_falsey + expect(Chef::Config[:color]).to be_truthy else expect(Chef::Config[:color]).to be_truthy end diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index 3c215eac7f..8894e86240 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -70,13 +70,13 @@ describe Chef::Application::Knife do end end - it "should set the colored output to false by default on windows and true otherwise" do + it "should set the colored output to true by default on windows and true on all other platforms as well" do with_argv(*%w{noop knife command}) do expect(@knife).to receive(:exit).with(0) @knife.run end if windows? - expect(Chef::Config[:color]).to be_falsey + expect(Chef::Config[:color]).to be_truthy else expect(Chef::Config[:color]).to be_truthy end diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index f736c38859..8fbf56844e 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -375,7 +375,8 @@ describe Chef::Client do expect(node[:roles].length).to eq(1) expect(node[:roles]).to include("role_containing_cookbook1") expect(node[:recipes]).not_to be_nil - expect(node[:recipes].length).to eq(1) + expect(node[:recipes].length).to eq(2) + expect(node[:recipes]).to include("cookbook1") expect(node[:recipes]).to include("cookbook1::default") expect(node[:expanded_run_list]).not_to be_nil expect(node[:expanded_run_list].length).to eq(1) diff --git a/spec/unit/event_dispatch/dispatcher_spec.rb b/spec/unit/event_dispatch/dispatcher_spec.rb index 1014feea89..5a06e1d6d1 100644 --- a/spec/unit/event_dispatch/dispatcher_spec.rb +++ b/spec/unit/event_dispatch/dispatcher_spec.rb @@ -73,8 +73,51 @@ describe Chef::EventDispatch::Dispatcher do expect(event_sink.synchronized_cookbook_args).to eq ["apache2"] end end - end -end + context "when two event sinks have different arguments for an event" do + let(:event_sink_1) do + Class.new(Chef::EventDispatch::Base) do + attr_reader :synchronized_cookbook_args + def synchronized_cookbook(cookbook_name) + @synchronized_cookbook_args = [cookbook_name] + end + end.new + end + let(:event_sink_2) do + Class.new(Chef::EventDispatch::Base) do + attr_reader :synchronized_cookbook_args + def synchronized_cookbook(cookbook_name, cookbook) + @synchronized_cookbook_args = [cookbook_name, cookbook] + end + end.new + end + + context "and the one with fewer arguments comes first" do + before do + dispatcher.register(event_sink_1) + dispatcher.register(event_sink_2) + end + it "trims the arugment list" do + cookbook_version = double("cookbook_version") + dispatcher.synchronized_cookbook("apache2", cookbook_version) + expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"] + expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version] + end + end + + context "and the one with fewer arguments comes last" do + before do + dispatcher.register(event_sink_2) + dispatcher.register(event_sink_1) + end + it "trims the arugment list" do + cookbook_version = double("cookbook_version") + dispatcher.synchronized_cookbook("apache2", cookbook_version) + expect(event_sink_1.synchronized_cookbook_args).to eq ["apache2"] + expect(event_sink_2.synchronized_cookbook_args).to eq ["apache2", cookbook_version] + end + end + end +end diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 9ecf7a4cde..dc06cb3326 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -921,6 +921,9 @@ describe "Chef::Resource.property" do expect(resource.x 10).to eq "101" expect(Namer.current_index).to eq 1 end + it "does not emit a deprecation warning if set to nil" do + expect(resource.x nil).to eq "1" + end it "coercion sets the value (and coercion does not run on get)" do expect(resource.x 10).to eq "101" expect(resource.x).to eq "101" @@ -933,6 +936,11 @@ describe "Chef::Resource.property" do expect(Namer.current_index).to eq 2 end end + with_property ':x, coerce: proc { |x| x }' do + it "does not emit a deprecation warning if set to nil" do + expect(resource.x nil).to be_nil + end + end with_property ':x, coerce: proc { |x| Namer.next_index; raise "hi" if x == 10; x }, is: proc { |x| Namer.next_index; x != 10 }' do it "failed coercion fails to set the value" do resource.x 20 diff --git a/spec/unit/provider/powershell_script_spec.rb b/spec/unit/provider/powershell_script_spec.rb index d06d2762be..121973763d 100644 --- a/spec/unit/provider/powershell_script_spec.rb +++ b/spec/unit/provider/powershell_script_spec.rb @@ -41,20 +41,30 @@ describe Chef::Provider::PowershellScript, "action_run" 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(:os_info).and_return(os_info_double) + allow(os_info_double).to receive(:system_directory).and_return("C:\\Windows\\system32") end it "sets the -Command flag as the last flag" do - expect(provider.flags.split(' ').pop).to eq("-Command") + flags = provider.command.split(' ').keep_if { |flag| flag =~ /^-/ } + expect(flags.pop).to eq("-Command") end 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(:os_info).and_return(os_info_double) + allow(os_info_double).to receive(:system_directory).and_return("C:\\Windows\\system32") end it "sets the -File flag as the last flag" do - expect(provider.flags.split(' ').pop).to eq("-File") + flags = provider.command.split(' ').keep_if { |flag| flag =~ /^-/ } + expect(flags.pop).to eq("-File") end let(:execution_policy_flag) do diff --git a/spec/unit/provider/user/windows_spec.rb b/spec/unit/provider/user/windows_spec.rb index e51e20a68f..7e08f971a9 100644 --- a/spec/unit/provider/user/windows_spec.rb +++ b/spec/unit/provider/user/windows_spec.rb @@ -107,8 +107,8 @@ describe Chef::Provider::User::Windows do expect(@provider.set_options[:home_dir]).to eq('/home/adam') end - it "marks the primary_group_id attribute to be updated" do - expect(@provider.set_options[:primary_group_id]).to eq(1000) + it "ignores the primary_group_id attribute" do + expect(@provider.set_options[:primary_group_id]).to eq(nil) end it "marks the user_id attribute to be updated" do diff --git a/spec/unit/resource/powershell_script_spec.rb b/spec/unit/resource/powershell_script_spec.rb index 2505c4a3d7..42fcd61a58 100644 --- a/spec/unit/resource/powershell_script_spec.rb +++ b/spec/unit/resource/powershell_script_spec.rb @@ -30,24 +30,28 @@ describe Chef::Resource::PowershellScript do run_context = Chef::RunContext.new(node, nil, nil) @resource = Chef::Resource::PowershellScript.new("powershell_unit_test", run_context) - end - it "should create a new Chef::Resource::PowershellScript" do + it "creates a new Chef::Resource::PowershellScript" do expect(@resource).to be_a_kind_of(Chef::Resource::PowershellScript) end - it "should set convert_boolean_return to false by default" do + it "sets convert_boolean_return to false by default" do expect(@resource.convert_boolean_return).to eq(false) end - it "should return the value for convert_boolean_return that was set" do + it "returns the value for convert_boolean_return that was set" do @resource.convert_boolean_return true expect(@resource.convert_boolean_return).to eq(true) @resource.convert_boolean_return false 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 @@ -62,32 +66,32 @@ describe Chef::Resource::PowershellScript do expect(inherited_difference).to eq([]) end - it "should allow guard interpreter to be set to Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::Script" do resource.guard_interpreter(:script) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should allow guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do resource.guard_interpreter(:bash) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should allow guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do + it "allows guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do resource.guard_interpreter(:powershell_script) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false) resource.only_if("echo hi") end - it "should enable convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do + it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {}) resource.only_if("$true") end - it "should enable convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do + it "enables convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do node = Chef::Node.new run_context = Chef::RunContext.new(node, nil, nil) file_resource = Chef::Resource::File.new('idontexist', run_context) @@ -98,21 +102,21 @@ describe Chef::Resource::PowershellScript do resource.only_if("$true") end - it "should enable convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do + it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64} allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end - it "should pass convert_boolean_return as true if it was specified as true in a guard parameter" do + it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do guard_parameters = {:cwd => '/etc/chef', :convert_boolean_return => true, :architecture => :x86_64} allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {}) resource.only_if("$true", guard_parameters) end - it "should pass convert_boolean_return as false if it was specified as true in a guard parameter" do + it "passes convert_boolean_return as false if it was specified as true in a guard parameter" do other_guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64} parameters_with_boolean_disabled = other_guard_parameters.merge({:convert_boolean_return => false, :code => "$true"}) allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with( @@ -127,6 +131,6 @@ describe Chef::Resource::PowershellScript do let(:resource_name) { :powershell_script } let(:interpreter_file_name) { 'powershell.exe' } - it_should_behave_like "a Windows script resource" + it_behaves_like "a Windows script resource" end end diff --git a/spec/unit/run_list/versioned_recipe_list_spec.rb b/spec/unit/run_list/versioned_recipe_list_spec.rb index 9c3ecaa0dd..be57d6c944 100644 --- a/spec/unit/run_list/versioned_recipe_list_spec.rb +++ b/spec/unit/run_list/versioned_recipe_list_spec.rb @@ -187,4 +187,9 @@ describe Chef::RunList::VersionedRecipeList do end end + context "with duplicated names", :chef_gte_13_only do + it "should fail in Chef 13" do + expect(list).to_not respond_to(:with_duplicate_names) + end + end end diff --git a/spec/unit/search/query_spec.rb b/spec/unit/search/query_spec.rb index 59ac80f228..f85b1760d4 100644 --- a/spec/unit/search/query_spec.rb +++ b/spec/unit/search/query_spec.rb @@ -83,6 +83,8 @@ describe Chef::Search::Query do describe "search" do let(:query_string) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0" } let(:query_string_continue) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=4" } + let(:query_string_with_rows) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=0&rows=4" } + let(:query_string_continue_with_rows) { "search/node?q=platform:rhel&sort=X_CHEF_id_CHEF_X%20asc&start=4&rows=4" } let(:response) { { "rows" => [ @@ -149,6 +151,14 @@ describe Chef::Search::Query do r } + let(:big_response_empty) { + { + "start" => 0, + "total" => 8, + "rows" => [] + } + } + let(:big_response_end) { r = response.dup r["start"] = 4 @@ -208,7 +218,7 @@ describe Chef::Search::Query do it "pages through the responses" do @call_me = double("blocky") response["rows"].each { |r| expect(@call_me).to receive(:do).with(r) } - query.search(:node, "*:*", sort: nil, start: 0, rows: 1) { |r| @call_me.do(r) } + query.search(:node, "*:*", sort: nil, start: 0, rows: 4) { |r| @call_me.do(r) } end it "sends multiple API requests when the server indicates there is more data" do @@ -219,6 +229,14 @@ describe Chef::Search::Query do end end + it "paginates correctly in the face of filtered nodes" do + expect(rest).to receive(:get_rest).with(query_string_with_rows).and_return(big_response_empty) + expect(rest).to receive(:get_rest).with(query_string_continue_with_rows).and_return(big_response_end) + query.search(:node, "platform:rhel", rows: 4) do |r| + nil + end + end + context "when :filter_result is provided as a result" do include_context "filtered search" do let(:filter_key) { :filter_result } |