summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-12-03 11:29:38 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-12-03 11:39:53 -0800
commit4f073bd4d4ca28f5cb60283df9ce35d21d5b7825 (patch)
tree841375ced5d4210a06d7eeedd189ddee6ae09971 /spec/unit
parent186a662eb649251572ca87b9f904fc0a85b30a31 (diff)
downloadchef-4f073bd4d4ca28f5cb60283df9ce35d21d5b7825.tar.gz
Fix knife plugin path searching
Unreleased Chef 12.0.0 bug caught in testing where only the searching upwards from PWD to find .chef in order to get the plugin path for knife was busted. The chef_config_dir was being used before load_config was being called, so it was nil, which broke finding knife plugins. This was fixed by adding some lazy initialization of the config_loader object itself and the chef_config_dir. The reset_config_loader! is added entirely to reset the global state for unit testing. This whole class is a bit horrible and needs to have all its global state removed from it, class methods removed, class ivars and the class-variable-in-a-class-method-for-inheritance-lolwut needs to be removed. Unfortunately, that requires some delicate surgery because Chef::Knife gets used as a public API, and is beyond the scope of gettting Chef 12 shipped.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/application/knife_spec.rb8
-rw-r--r--spec/unit/knife_spec.rb5
2 files changed, 11 insertions, 2 deletions
diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb
index 0933d7e178..09a953ee0e 100644
--- a/spec/unit/application/knife_spec.rb
+++ b/spec/unit/application/knife_spec.rb
@@ -33,6 +33,11 @@ describe Chef::Application::Knife do
end
end
+ after(:each) do
+ # reset some really nasty global state
+ NoopKnifeCommand.reset_config_loader!
+ end
+
before(:each) do
# Prevent code from getting loaded on every test invocation.
Chef::Knife.stub(:load_commands)
@@ -109,7 +114,6 @@ describe Chef::Application::Knife do
end
Chef::Config[:client_key].should == full_path
end
-
end
describe "with environment configuration" do
@@ -168,6 +172,6 @@ describe Chef::Application::Knife do
@knife.run
end
end
-
end
+
end
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 6d4763e087..2cd1d8b646 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -44,6 +44,10 @@ describe Chef::Knife do
@stderr = StringIO.new
end
+ after(:each) do
+ Chef::Knife.reset_config_loader!
+ end
+
describe "after loading a subcommand" do
before do
Chef::Knife.reset_subcommands!
@@ -268,6 +272,7 @@ describe Chef::Knife do
@knife.config[:verbosity] = 1
@knife.config[:config_file] = fake_config
config_loader = double("Chef::WorkstationConfigLoader", :load => true, :no_config_found? => false, :chef_config_dir => "/etc/chef", :config_location => fake_config)
+ allow(config_loader).to receive(:explicit_config_file=).with(fake_config).and_return(fake_config)
allow(Chef::WorkstationConfigLoader).to receive(:new).and_return(config_loader)
end