diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/support/shared/functional/securable_resource.rb | 4 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 20 | ||||
-rw-r--r-- | spec/unit/knife/core/node_editor_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/knife/node_edit_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 3 | ||||
-rw-r--r-- | spec/unit/policy_builder/policyfile_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/provider/package/rubygems_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/provider/service/windows_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider_resolver_spec.rb | 41 | ||||
-rw-r--r-- | spec/unit/server_api_spec.rb | 30 |
10 files changed, 76 insertions, 52 deletions
diff --git a/spec/support/shared/functional/securable_resource.rb b/spec/support/shared/functional/securable_resource.rb index 95f4f4bd49..2ca93bdcd0 100644 --- a/spec/support/shared/functional/securable_resource.rb +++ b/spec/support/shared/functional/securable_resource.rb @@ -81,7 +81,7 @@ shared_context "use Windows permissions", :windows_only do SID ||= Chef::ReservedNames::Win32::Security::SID ACE ||= Chef::ReservedNames::Win32::Security::ACE ACL ||= Chef::ReservedNames::Win32::Security::ACL - SecurableObject ||= Chef::ReservedNames::Win32::Security::SecurableObject # rubocop:disable Style/ConstantName + SecurableObject ||= Chef::ReservedNames::Win32::Security::SecurableObject # rubocop:disable Naming/ConstantName end def get_security_descriptor(path) @@ -439,7 +439,7 @@ shared_examples_for "a securable resource without existing target" do context "with a mode attribute" do if windows? - Security ||= Chef::ReservedNames::Win32::API::Security # rubocop:disable Style/ConstantName + Security ||= Chef::ReservedNames::Win32::API::Security # rubocop:disable Naming/ConstantName end it "respects mode in string form as an octal number" do diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index ea4c177d55..81c0b8a6cf 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -96,24 +96,8 @@ describe Chef::Knife::Bootstrap do end end - context "with :distro and :bootstrap_template cli options" do - let(:bootstrap_cli_options) { [ "--bootstrap-template", "my-template", "--distro", "other-template" ] } - - it "should select bootstrap template" do - expect(File.basename(knife.bootstrap_template)).to eq("my-template") - end - end - - context "with :distro and :template_file cli options" do - let(:bootstrap_cli_options) { [ "--distro", "my-template", "--template-file", "other-template" ] } - - it "should select bootstrap template" do - expect(File.basename(knife.bootstrap_template)).to eq("other-template") - end - end - context "with :bootstrap_template and :template_file cli options" do - let(:bootstrap_cli_options) { [ "--bootstrap-template", "my-template", "--template-file", "other-template" ] } + let(:bootstrap_cli_options) { [ "--bootstrap-template", "my-template", "other-template" ] } it "should select bootstrap template" do expect(File.basename(knife.bootstrap_template)).to eq("my-template") @@ -247,7 +231,7 @@ describe Chef::Knife::Bootstrap do end end - ["-d", "--distro", "-t", "--bootstrap-template", "--template-file"].each do |t| + ["-t", "--bootstrap-template"].each do |t| context "when #{t} option is given in the command line" do it "sets the knife :bootstrap_template config" do knife.parse_options([t, "blahblah"]) diff --git a/spec/unit/knife/core/node_editor_spec.rb b/spec/unit/knife/core/node_editor_spec.rb index 7e05f99f52..a3dd63177d 100644 --- a/spec/unit/knife/core/node_editor_spec.rb +++ b/spec/unit/knife/core/node_editor_spec.rb @@ -100,10 +100,10 @@ describe Chef::Knife::NodeEditor do expect(updated_node).to be_a(Chef::Node) # Expected to have been changed - expect(updated_node.chef_environment).to eql(updated_data["chef_environment"]) expect(updated_node.normal_attrs).to eql(updated_data["normal"]) expect(updated_node.policy_name).to eql(updated_data["policy_name"]) expect(updated_node.policy_group).to eql(updated_data["policy_group"]) + expect(updated_node.chef_environment).to eql(updated_data["policy_group"]) expect(updated_node.run_list.map(&:to_s)).to eql(updated_data["run_list"]) # Expected not to have changed @@ -131,7 +131,7 @@ describe Chef::Knife::NodeEditor do updated_node = subject.apply_updates(updated_data) expect(updated_node).to be_a(Chef::Node) - expect(updated_node.chef_environment).to eql(updated_data["chef_environment"]) + expect(updated_node.chef_environment).to eql(updated_data["policy_group"]) expect(updated_node.automatic_attrs).to eql(updated_data["automatic"]) expect(updated_node.normal_attrs).to eql(updated_data["normal"]) expect(updated_node.default_attrs).to eql(updated_data["default"]) @@ -173,7 +173,7 @@ describe Chef::Knife::NodeEditor do end it "returns an array of the changed property names" do - expect(subject.updated?).to eql %w{ normal policy_name policy_group run_list } + expect(subject.updated?).to eql %w{ chef_environment normal policy_name policy_group run_list } end end @@ -190,7 +190,7 @@ describe Chef::Knife::NodeEditor do it "returns an array of property names that doesn't include " + "the non-editable properties" do - expect(subject.updated?).to eql %w{ normal policy_name policy_group run_list } + expect(subject.updated?).to eql %w{ chef_environment normal policy_name policy_group run_list } end end end diff --git a/spec/unit/knife/node_edit_spec.rb b/spec/unit/knife/node_edit_spec.rb index dedb5c949d..e5fa9317b1 100644 --- a/spec/unit/knife/node_edit_spec.rb +++ b/spec/unit/knife/node_edit_spec.rb @@ -23,7 +23,7 @@ describe Chef::Knife::NodeEdit do # helper to convert the view from Chef objects into Ruby objects representing JSON def deserialized_json_view - actual = Chef::JSONCompat.from_json(Chef::JSONCompat.to_json_pretty(@knife.node_editor.send(:view))) + Chef::JSONCompat.from_json(Chef::JSONCompat.to_json_pretty(@knife.node_editor.send(:view))) end before(:each) do @@ -45,6 +45,8 @@ describe Chef::Knife::NodeEdit do describe "after loading the node" do before do + @knife.config[:all_attributes] = false + allow(@knife).to receive(:node).and_return(@node) @node.automatic_attrs = { :go => :away } @node.default_attrs = { :hide => :me } diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 2019f1ac42..df85b79fc5 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -186,7 +186,7 @@ describe Chef::Node do expect { node.policy_group = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqurstuvwxyz0123456789-_:." }.to_not raise_error end - it "sets an environment with chef_environment(something)" do + it "sets a policy_group with policy_group(something)" do node.policy_group("staging") expect(node.policy_group).to eq("staging") end @@ -1353,6 +1353,7 @@ describe Chef::Node do expect(round_tripped_node.policy_name).to eq("my-application") expect(round_tripped_node.policy_group).to eq("staging") + expect(round_tripped_node.chef_environment).to eq("staging") end end diff --git a/spec/unit/policy_builder/policyfile_spec.rb b/spec/unit/policy_builder/policyfile_spec.rb index b8cf56750d..5663cb8b19 100644 --- a/spec/unit/policy_builder/policyfile_spec.rb +++ b/spec/unit/policy_builder/policyfile_spec.rb @@ -574,6 +574,10 @@ describe Chef::PolicyBuilder::Policyfile do expect(Chef::Config[:policy_group]).to eq("policy_group_from_node_json") expect(node.policy_name).to eq("policy_name_from_node_json") expect(node.policy_group).to eq("policy_group_from_node_json") + expect(node.automatic_attrs[:policy_name]).to eq("policy_name_from_node_json") + expect(node.automatic_attrs[:policy_group]).to eq("policy_group_from_node_json") + expect(node.automatic_attrs[:chef_environment]).to eq("policy_group_from_node_json") + end end @@ -623,6 +627,7 @@ describe Chef::PolicyBuilder::Policyfile do it "create node.automatic_attrs[:recipes]" do expect(node.automatic_attrs[:recipes]).to eq(["example1::default", "example2::server"]) end + end context "when a named run_list is given" do diff --git a/spec/unit/provider/package/rubygems_spec.rb b/spec/unit/provider/package/rubygems_spec.rb index ac2b511ca9..071cba23d8 100644 --- a/spec/unit/provider/package/rubygems_spec.rb +++ b/spec/unit/provider/package/rubygems_spec.rb @@ -43,7 +43,10 @@ describe Chef::Provider::Package::Rubygems::CurrentGemEnvironment do it "determines the installed versions of gems from Gem.source_index" do gems = [gemspec("rspec-core", Gem::Version.new("1.2.9")), gemspec("rspec-core", Gem::Version.new("1.3.0"))] - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.0") + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") + expect(Gem::Specification).to receive(:dirs).and_return(["/path/to/gems/specifications", "/another/path/to/gems/specifications"]) + expect(Gem::Specification).to receive(:installed_stubs).with(["/path/to/gems/specifications", "/another/path/to/gems/specifications"], "rspec-core-*.gemspec").and_return(gems) + elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.0") expect(Gem::Specification).to receive(:find_all_by_name).with("rspec-core", Gem::Dependency.new("rspec-core").requirement).and_return(gems) else expect(Gem.source_index).to receive(:search).with(Gem::Dependency.new("rspec-core", nil)).and_return(gems) @@ -219,7 +222,11 @@ describe Chef::Provider::Package::Rubygems::AlternateGemEnvironment do it "determines the installed versions of gems from the source index" do gems = [gemspec("rspec", Gem::Version.new("1.2.9")), gemspec("rspec", Gem::Version.new("1.3.0"))] rspec_dep = Gem::Dependency.new("rspec", nil) - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.0") + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("2.7") + allow(@gem_env).to receive(:gem_specification).and_return(Gem::Specification) + expect(Gem::Specification).to receive(:dirs).and_return(["/path/to/gems/specifications", "/another/path/to/gems/specifications"]) + expect(Gem::Specification).to receive(:installed_stubs).with(["/path/to/gems/specifications", "/another/path/to/gems/specifications"], "rspec-*.gemspec").and_return(gems) + elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.8.0") allow(@gem_env).to receive(:gem_specification).and_return(Gem::Specification) expect(@gem_env.gem_specification).to receive(:find_all_by_name).with(rspec_dep.name, rspec_dep.requirement).and_return(gems) else diff --git a/spec/unit/provider/service/windows_spec.rb b/spec/unit/provider/service/windows_spec.rb index edc409fab0..ce9154cb72 100644 --- a/spec/unit/provider/service/windows_spec.rb +++ b/spec/unit/provider/service/windows_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" require "mixlib/shellout" -describe Chef::Provider::Service::Windows, "load_current_resource" do +describe Chef::Provider::Service::Windows, "load_current_resource", :windows_only do include_context "Win32" let(:chef_service_name) { "chef-client" } diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb index 6fa05c936a..a913c82a1e 100644 --- a/spec/unit/provider_resolver_spec.rb +++ b/spec/unit/provider_resolver_spec.rb @@ -553,6 +553,8 @@ describe Chef::ProviderResolver do PROVIDERS = { + aix_user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ], + apt_package: [ Chef::Resource::AptPackage, Chef::Provider::Package::Apt ], bash: [ Chef::Resource::Bash, Chef::Provider::Script ], bff_package: [ Chef::Resource::BffPackage, Chef::Provider::Package::Bff ], breakpoint: [ Chef::Resource::Breakpoint, Chef::Resource::Breakpoint.action_class ], @@ -560,6 +562,9 @@ describe Chef::ProviderResolver do cookbook_file: [ Chef::Resource::CookbookFile, Chef::Provider::CookbookFile ], csh: [ Chef::Resource::Csh, Chef::Provider::Script ], directory: [ Chef::Resource::Directory, Chef::Provider::Directory ], + dpkg_package: [ Chef::Resource::DpkgPackage, Chef::Provider::Package::Dpkg ], + dsc_script: [ Chef::Resource::DscScript, Chef::Provider::DscScript ], + dscl_user: [ Chef::Resource::User::DsclUser, Chef::Provider::User::Dscl ], execute: [ Chef::Resource::Execute, Chef::Provider::Execute ], file: [ Chef::Resource::File, Chef::Provider::File ], gem_package: [ Chef::Resource::GemPackage, Chef::Provider::Package::Rubygems ], @@ -568,49 +573,39 @@ describe Chef::ProviderResolver do homebrew_package: [ Chef::Resource::HomebrewPackage, Chef::Provider::Package::Homebrew ], http_request: [ Chef::Resource::HttpRequest, Chef::Provider::HttpRequest ], ifconfig: [ Chef::Resource::Ifconfig, Chef::Provider::Ifconfig ], + ips_package: [ Chef::Resource::IpsPackage, Chef::Provider::Package::Ips ], link: [ Chef::Resource::Link, Chef::Provider::Link ], + linux_user: [ Chef::Resource::User::LinuxUser, Chef::Provider::User::Linux ], log: [ Chef::Resource::Log, Chef::Provider::Log::ChefLog ], macports_package: [ Chef::Resource::MacportsPackage, Chef::Provider::Package::Macports ], mdadm: [ Chef::Resource::Mdadm, Chef::Provider::Mdadm ], mount: [ Chef::Resource::Mount, Chef::Provider::Mount::Mount ], + pacman_package: [ Chef::Resource::PacmanPackage, Chef::Provider::Package::Pacman ], + paludis_package: [ Chef::Resource::PaludisPackage, Chef::Provider::Package::Paludis ], perl: [ Chef::Resource::Perl, Chef::Provider::Script ], portage_package: [ Chef::Resource::PortagePackage, Chef::Provider::Package::Portage ], + pw_user: [ Chef::Resource::User::PwUser, Chef::Provider::User::Pw ], python: [ Chef::Resource::Python, Chef::Provider::Script ], remote_directory: [ Chef::Resource::RemoteDirectory, Chef::Provider::RemoteDirectory ], route: [ Chef::Resource::Route, Chef::Provider::Route ], - ruby: [ Chef::Resource::Ruby, Chef::Provider::Script ], + rpm_package: [ Chef::Resource::Package::RpmPackage, Chef::Provider::Package::Rpm ], ruby_block: [ Chef::Resource::RubyBlock, Chef::Provider::RubyBlock ], + ruby: [ Chef::Resource::Ruby, Chef::Provider::Script ], script: [ Chef::Resource::Script, Chef::Provider::Script ], + smartos_package: [ Chef::Resource::SmartosPackage, Chef::Provider::Package::SmartOS ], + solaris_package: [ Chef::Resource::SolarisPackage, Chef::Provider::Package::Solaris ], + solaris_user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ], subversion: [ Chef::Resource::Subversion, Chef::Provider::Subversion ], template: [ Chef::Resource::Template, Chef::Provider::Template ], - aix_user: [ Chef::Resource::User::AixUser, Chef::Provider::User::Aix ], - dscl_user: [ Chef::Resource::User::DsclUser, Chef::Provider::User::Dscl ], - linux_user: [ Chef::Resource::User::LinuxUser, Chef::Provider::User::Linux ], - pw_user: [ Chef::Resource::User::PwUser, Chef::Provider::User::Pw ], - solaris_user: [ Chef::Resource::User::SolarisUser, Chef::Provider::User::Solaris ], - windows_user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ], whyrun_safe_ruby_block: [ Chef::Resource::WhyrunSafeRubyBlock, Chef::Provider::WhyrunSafeRubyBlock ], + windows_package: [ Chef::Resource::WindowsPackage, Chef::Provider::Package::Windows ], + windows_service: [ Chef::Resource::WindowsService, Chef::Provider::Service::Windows ], + windows_user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ], # We want to check that these are unsupported: - apt_package: nil, - dpkg_package: nil, - dsc_script: nil, - ips_package: nil, - pacman_package: nil, - paludis_package: nil, - rpm_package: nil, - smartos_package: nil, - solaris_package: nil, yum_package: nil, - windows_package: nil, - windows_service: nil, "linux" => { - apt_package: [ Chef::Resource::AptPackage, Chef::Provider::Package::Apt ], - dpkg_package: [ Chef::Resource::DpkgPackage, Chef::Provider::Package::Dpkg ], - pacman_package: [ Chef::Resource::PacmanPackage, Chef::Provider::Package::Pacman ], - paludis_package: [ Chef::Resource::PaludisPackage, Chef::Provider::Package::Paludis ], - rpm_package: [ Chef::Resource::RpmPackage, Chef::Provider::Package::Rpm ], yum_package: [ Chef::Resource::YumPackage, Chef::Provider::Package::Yum ], "debian" => { diff --git a/spec/unit/server_api_spec.rb b/spec/unit/server_api_spec.rb index 3f1d9b0e90..c64f42d358 100644 --- a/spec/unit/server_api_spec.rb +++ b/spec/unit/server_api_spec.rb @@ -58,6 +58,36 @@ describe Chef::ServerAPI do end end + describe "#get" do + context "when response is 404" do + context "body data is not json" do + it "throws not a Chef server exception" do + net_http_not_found = double() + allow(net_http_not_found).to receive(:kind_of?).and_return(Net::HTTPNotFound) + allow(net_http_not_found).to receive(:body).and_return("Not Found") + + api = described_class.new(url, raw_key: SIGNING_KEY_DOT_PEM) + allow(api).to receive(:request).and_raise(Net::HTTPServerException.new("", net_http_not_found)) + + expect { api.get("/nodes") }.to raise_error(Chef::Exceptions::NotAChefServerException) + end + end + + context "body data is json" do + it "bubbles up Exception" do + net_http_not_found = double() + allow(net_http_not_found).to receive(:kind_of?).and_return(Net::HTTPNotFound) + allow(net_http_not_found).to receive(:body).and_return("{}") + + api = described_class.new(url, raw_key: SIGNING_KEY_DOT_PEM) + allow(api).to receive(:request).and_raise(Net::HTTPServerException.new("", net_http_not_found)) + + expect { api.get("/nodes") }.to raise_error(Net::HTTPServerException) + end + end + end + end + context "versioned apis" do class VersionedClassV0 extend Chef::Mixin::VersionedAPI |