summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/config_spec.rb7
-rw-r--r--spec/unit/cookbook/chefignore_spec.rb3
-rw-r--r--spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb20
-rw-r--r--spec/unit/knife/bootstrap_spec.rb97
-rw-r--r--spec/unit/knife/core/bootstrap_context_spec.rb7
-rw-r--r--spec/unit/provider/package/yum_spec.rb90
-rw-r--r--spec/unit/resource/log_spec.rb9
7 files changed, 193 insertions, 40 deletions
diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb
index 927e7059b1..7b5d383ba3 100644
--- a/spec/unit/config_spec.rb
+++ b/spec/unit/config_spec.rb
@@ -104,7 +104,14 @@ describe Chef::Config do
@config_class.formatters.should == [[:doc, "/var/log/formatter.log"]]
end
+ end
+ context "when the url is a frozen string" do
+ before do
+ Chef::Config.chef_server_url = " https://junglist.gen.nz".freeze
+ end
+
+ it_behaves_like "server URL"
end
describe "class method: manage_secret_key" do
diff --git a/spec/unit/cookbook/chefignore_spec.rb b/spec/unit/cookbook/chefignore_spec.rb
index 30b97e865d..aacb60c012 100644
--- a/spec/unit/cookbook/chefignore_spec.rb
+++ b/spec/unit/cookbook/chefignore_spec.rb
@@ -23,7 +23,7 @@ describe Chef::Cookbook::Chefignore do
end
it "loads the globs in the chefignore file" do
- @chefignore.ignores.should =~ %w[recipes/ignoreme.rb]
+ @chefignore.ignores.should =~ %w[recipes/ignoreme.rb ignored]
end
it "removes items from an array that match the ignores" do
@@ -32,6 +32,7 @@ describe Chef::Cookbook::Chefignore do
end
it "determines if a file is ignored" do
+ @chefignore.ignored?('ignored').should be_true
@chefignore.ignored?('recipes/ignoreme.rb').should be_true
@chefignore.ignored?('recipes/dontignoreme.rb').should be_false
end
diff --git a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
index 52c719d2fb..fa96845aca 100644
--- a/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
+++ b/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb
@@ -112,6 +112,7 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do
# fake code to run through #recipe_snippet
source_file = [ "if true", "var = non_existant", "end" ]
IO.stub!(:readlines).and_return(source_file)
+ File.stub!(:exists?).and_return(true)
end
it "parses a Windows path" do
@@ -127,6 +128,25 @@ describe Chef::Formatters::ErrorInspectors::ResourceFailureInspector do
@inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception)
@inspector.recipe_snippet.should match(/^# In \/home\/btm/)
end
+
+ context "when the recipe file does not exist" do
+ before do
+ File.stub!(:exists?).and_return(false)
+ IO.stub!(:readlines).and_raise(Errno::ENOENT)
+ end
+
+ it "does not try to parse a recipe in chef-shell/irb (CHEF-3411)" do
+ @resource.source_line = "(irb#1):1:in `irb_binding'"
+ @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception)
+ @inspector.recipe_snippet.should be_nil
+ end
+
+ it "does not raise an exception trying to load a non-existant file (CHEF-3411)" do
+ @resource.source_line = "/somewhere/in/space"
+ @inspector = Chef::Formatters::ErrorInspectors::ResourceFailureInspector.new(@resource, :create, @exception)
+ lambda { @inspector.recipe_snippet }.should_not raise_error
+ end
+ end
end
describe "when examining a resource that confuses the parser" do
diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb
index 98955d4f73..bbb63f8c01 100644
--- a/spec/unit/knife/bootstrap_spec.rb
+++ b/spec/unit/knife/bootstrap_spec.rb
@@ -134,36 +134,77 @@ describe Chef::Knife::Bootstrap do
@knife.name_args.first.should == "barf"
end
- describe "when configuring the underlying knife ssh command" do
- before do
- @knife.name_args = ["foo.example.com"]
- @knife.config[:ssh_user] = "rooty"
- @knife.config[:ssh_password] = "open_sesame"
- Chef::Config[:knife][:ssh_port] = "4001"
- @knife.config[:identity_file] = "~/.ssh/me.rsa"
- @knife.stub!(:read_template).and_return("")
- @knife_ssh = @knife.knife_ssh
- end
-
- it "configures the hostname" do
- @knife_ssh.name_args.first.should == "foo.example.com"
+ describe "when configuring the underlying knife ssh command"
+ context "from the command line" do
+ before do
+ @knife.name_args = ["foo.example.com"]
+ @knife.config[:ssh_user] = "rooty"
+ @knife.config[:ssh_port] = "4001"
+ @knife.config[:ssh_password] = "open_sesame"
+ Chef::Config[:knife][:ssh_user] = nil
+ Chef::Config[:knife][:ssh_port] = nil
+ @knife.config[:identity_file] = "~/.ssh/me.rsa"
+ @knife.stub!(:read_template).and_return("")
+ @knife_ssh = @knife.knife_ssh
+ end
+
+ it "configures the hostname" do
+ @knife_ssh.name_args.first.should == "foo.example.com"
+ end
+
+ it "configures the ssh user" do
+ @knife_ssh.config[:ssh_user].should == 'rooty'
+ end
+
+ it "configures the ssh password" do
+ @knife_ssh.config[:ssh_password].should == 'open_sesame'
+ end
+
+ it "configures the ssh port" do
+ @knife_ssh.config[:ssh_port].should == '4001'
+ end
+
+ it "configures the ssh identity file" do
+ @knife_ssh.config[:identity_file].should == '~/.ssh/me.rsa'
+ end
end
- it "configures the ssh user" do
- @knife_ssh.config[:ssh_user].should == 'rooty'
- end
-
- it "configures the ssh password" do
- @knife_ssh.config[:ssh_password].should == 'open_sesame'
- end
-
- it "configures the ssh port" do
- @knife_ssh.config[:ssh_port].should == '4001'
- end
-
- it "configures the ssh identity file" do
- @knife_ssh.config[:identity_file].should == '~/.ssh/me.rsa'
- end
+ context "from the knife config file" do
+ before do
+ @knife.name_args = ["config.example.com"]
+ @knife.config[:ssh_user] = nil
+ @knife.config[:ssh_port] = nil
+ @knife.config[:ssh_gateway] = nil
+ @knife.config[:identity_file] = nil
+ @knife.config[:host_key_verify] = nil
+ Chef::Config[:knife][:ssh_user] = "curiosity"
+ Chef::Config[:knife][:ssh_port] = "2430"
+ Chef::Config[:knife][:identity_file] = "~/.ssh/you.rsa"
+ Chef::Config[:knife][:ssh_gateway] = "towel.blinkenlights.nl"
+ Chef::Config[:knife][:host_key_verify] = true
+ @knife.stub!(:read_template).and_return("")
+ @knife_ssh = @knife.knife_ssh
+ end
+
+ it "configures the ssh user" do
+ @knife_ssh.config[:ssh_user].should == 'curiosity'
+ end
+
+ it "configures the ssh port" do
+ @knife_ssh.config[:ssh_port].should == '2430'
+ end
+
+ it "configures the ssh identity file" do
+ @knife_ssh.config[:identity_file].should == '~/.ssh/you.rsa'
+ end
+
+ it "configures the ssh gateway" do
+ @knife_ssh.config[:ssh_gateway].should == 'towel.blinkenlights.nl'
+ end
+
+ it "configures the host key verify mode" do
+ @knife_ssh.config[:host_key_verify].should == true
+ end
end
describe "when falling back to password auth when host key auth fails" do
diff --git a/spec/unit/knife/core/bootstrap_context_spec.rb b/spec/unit/knife/core/bootstrap_context_spec.rb
index 6e1ce97f40..65c02beff0 100644
--- a/spec/unit/knife/core/bootstrap_context_spec.rb
+++ b/spec/unit/knife/core/bootstrap_context_spec.rb
@@ -56,6 +56,13 @@ describe Chef::Knife::Core::BootstrapContext do
@context.validation_key.should == IO.read(File.join(CHEF_SPEC_DATA, 'ssl', 'private_key.pem'))
end
+ it "reads the validation key when it contains a ~" do
+ IO.should_receive(:read).with(File.expand_path("my.key", ENV['HOME']))
+ @chef_config = {:validation_key => '~/my.key'}
+ @context = Chef::Knife::Core::BootstrapContext.new(@config, @run_list, @chef_config)
+ @context.validation_key
+ end
+
it "generates the config file data" do
expected=<<-EXPECTED
log_level :auto
diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb
index 4b890b1549..375ae0966b 100644
--- a/spec/unit/provider/package/yum_spec.rb
+++ b/spec/unit/provider/package/yum_spec.rb
@@ -34,7 +34,8 @@ describe Chef::Provider::Package::Yum do
:package_available? => true,
:version_available? => true,
:allow_multi_install => [ "kernel" ],
- :package_repository => "base"
+ :package_repository => "base",
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -92,6 +93,7 @@ describe Chef::Provider::Package::Yum do
end
end
@yum_cache.stub!(:package_available?).and_return(true)
+ @yum_cache.stub!(:disable_extra_repo_control).and_return(true)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@provider.load_current_resource
@@ -125,6 +127,7 @@ describe Chef::Provider::Package::Yum do
nil
end
@yum_cache.stub!(:package_available?).and_return(true)
+ @yum_cache.stub!(:disable_extra_repo_control).and_return(true)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
# annoying side effect of the fun stub'ing above
@@ -155,6 +158,7 @@ describe Chef::Provider::Package::Yum do
nil
end
@yum_cache.stub!(:package_available?).and_return(true)
+ @yum_cache.stub!(:disable_extra_repo_control).and_return(true)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@provider.load_current_resource
@@ -189,6 +193,7 @@ describe Chef::Provider::Package::Yum do
end
end.and_return("something")
@yum_cache.stub!(:package_available?).and_return(true)
+ @yum_cache.stub!(:disable_extra_repo_control).and_return(true)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@provider.load_current_resource
@@ -209,6 +214,24 @@ describe Chef::Provider::Package::Yum do
@provider.load_current_resource
end
+ it "should detect --enablerepo or --disablerepo when passed among options, collect them preserving order and notify the yum cache" do
+ @new_resource.stub!(:options).and_return("--stuff --enablerepo=foo --otherthings --disablerepo=a,b,c --enablerepo=bar")
+ @yum_cache.should_receive(:enable_extra_repo_control).with("--enablerepo=foo --disablerepo=a,b,c --enablerepo=bar")
+ @provider.load_current_resource
+ end
+
+ it "should let the yum cache know extra repos are disabled if --enablerepo or --disablerepo aren't among options" do
+ @new_resource.stub!(:options).and_return("--stuff --otherthings")
+ @yum_cache.should_receive(:disable_extra_repo_control)
+ @provider.load_current_resource
+ end
+
+ it "should let the yum cache know extra repos are disabled if options aren't set" do
+ @new_resource.stub!(:options).and_return(nil)
+ @yum_cache.should_receive(:disable_extra_repo_control)
+ @provider.load_current_resource
+ end
+
it "should search provides if package name can't be found then set package_name to match" do
@yum_cache = mock(
'Chef::Provider::Yum::YumCache',
@@ -217,7 +240,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5",
:package_available? => false,
- :version_available? => true
+ :version_available? => true,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "1.2.4-11.18.el5", "x86_64", [])
@@ -235,7 +259,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5",
:package_available? => false,
- :version_available? => true
+ :version_available? => true,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
pkg_x = Chef::Provider::Package::Yum::RPMPackage.new("test-package-x", "1.2.4-11.18.el5", "x86_64", [])
@@ -255,7 +280,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5",
:package_available? => false,
- :version_available? => true
+ :version_available? => true,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@yum_cache.should_receive(:packages_from_require).twice.and_return([])
@@ -272,7 +298,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5",
:package_available? => false,
- :version_available? => true
+ :version_available? => true,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -295,7 +322,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5",
:package_available? => false,
- :version_available? => true
+ :version_available? => true,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@yum_cache.should_receive(:packages_from_require).twice.and_return([])
@@ -363,7 +391,8 @@ describe Chef::Provider::Package::Yum do
:installed_version => "1.2.4-11.18.el5",
:candidate_version => "1.2.4-11.18.el5_2.3",
:package_available? => true,
- :version_available? => nil
+ :version_available? => nil,
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -380,7 +409,8 @@ describe Chef::Provider::Package::Yum do
:candidate_version => "1.2.4-11.15.el5",
:package_available? => true,
:version_available? => true,
- :allow_multi_install => [ "kernel" ]
+ :allow_multi_install => [ "kernel" ],
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -398,7 +428,8 @@ describe Chef::Provider::Package::Yum do
:package_available? => true,
:version_available? => true,
:allow_multi_install => [ "cups" ],
- :package_repository => "base"
+ :package_repository => "base",
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -420,7 +451,8 @@ describe Chef::Provider::Package::Yum do
:package_available? => true,
:version_available? => true,
:allow_multi_install => [],
- :package_repository => "base"
+ :package_repository => "base",
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -485,7 +517,8 @@ describe Chef::Provider::Package::Yum do
:candidate_version => "1.2.4-11.15.el5",
:package_available? => true,
:version_available? => true,
- :allow_multi_install => [ "kernel" ]
+ :allow_multi_install => [ "kernel" ],
+ :disable_extra_repo_control => true
)
Chef::Provider::Package::Yum::YumCache.stub!(:instance).and_return(@yum_cache)
@provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
@@ -1609,6 +1642,12 @@ EOF
@yc.refresh
end
+ it "should pass extra_repo_control args to yum-dump.py" do
+ @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar")
+ @yc.should_receive(:popen4).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar$}, :waitlast=>true)
+ @yc.refresh
+ end
+
it "should warn about invalid data with too many separators" do
@yc.stub!(:popen4).and_yield(@pid, @stdin, @stdout_bad_separators, @stderr).and_return(@status)
Chef::Log.should_receive(:warn).exactly(3).times.with(%r{Problem parsing})
@@ -1788,4 +1827,33 @@ EOF
end
end
+ describe "enable_extra_repo_control" do
+ it "should set @extra_repo_control to arg" do
+ @yc.enable_extra_repo_control("--enablerepo=test")
+ @yc.extra_repo_control.should be == "--enablerepo=test"
+ end
+
+ it "should call reload once when set to flag cache for update" do
+ @yc.should_receive(:reload).once
+ @yc.enable_extra_repo_control("--enablerepo=test")
+ @yc.enable_extra_repo_control("--enablerepo=test")
+ end
+ end
+
+ describe "disable_extra_repo_control" do
+ it "should set @extra_repo_control to nil" do
+ @yc.enable_extra_repo_control("--enablerepo=test")
+ @yc.disable_extra_repo_control
+ @yc.extra_repo_control.should be == nil
+ end
+
+ it "should call reload once when cleared to flag cache for update" do
+ @yc.should_receive(:reload).once
+ @yc.enable_extra_repo_control("--enablerepo=test")
+ @yc.should_receive(:reload).once
+ @yc.disable_extra_repo_control
+ @yc.disable_extra_repo_control
+ end
+ end
+
end
diff --git a/spec/unit/resource/log_spec.rb b/spec/unit/resource/log_spec.rb
index bc5ac13078..4c6b2c122d 100644
--- a/spec/unit/resource/log_spec.rb
+++ b/spec/unit/resource/log_spec.rb
@@ -38,6 +38,15 @@ describe Chef::Resource::Log do
it "should allow you to set a log string" do
@resource.name.should == @log_str
end
+
+ it "should set the message to the first argument to new" do
+ @resource.message.should == @log_str
+ end
+
+ it "should accept a string for the log message" do
+ @resource.message "this is different"
+ @resource.message.should == "this is different"
+ end
it "should accept a vaild level option" do
@resource.level :debug