diff options
author | danielsdeleo <dan@opscode.com> | 2013-01-14 16:22:44 -0800 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-01-14 17:28:02 -0800 |
commit | 136ce0b0c9dff13e69e442f6c22b5edc71981c1c (patch) | |
tree | 82daf40b73658d1e5d627614ba4926ebe818a03e /spec | |
parent | b09dd3272d2557c4722120f89b212bfe72ed7ec3 (diff) | |
download | chef-136ce0b0c9dff13e69e442f6c22b5edc71981c1c.tar.gz |
[CHEF-3497] apply config in the desired order
Takes advantage of new mixlib-cli option to keep default values from the
mixlib-cli DSL separate from user-supplied values. Config settings are
merged:
1. Defaults from mixlib-cli DSL
2. Settings from Chef::Config[:knife]
3. Values from CLI options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/application/knife_spec.rb | 5 | ||||
-rw-r--r-- | spec/unit/knife/bootstrap_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/knife/ssh_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/knife_spec.rb | 30 |
4 files changed, 38 insertions, 0 deletions
diff --git a/spec/unit/application/knife_spec.rb b/spec/unit/application/knife_spec.rb index 78a65e7045..9560de8d13 100644 --- a/spec/unit/application/knife_spec.rb +++ b/spec/unit/application/knife_spec.rb @@ -23,6 +23,11 @@ describe Chef::Application::Knife do before(:all) do class NoopKnifeCommand < Chef::Knife + option :opt_with_default, + :short => "-D VALUE", + :long => "-optwithdefault VALUE", + :default => "default-value" + def run end end diff --git a/spec/unit/knife/bootstrap_spec.rb b/spec/unit/knife/bootstrap_spec.rb index 76261d96ab..98955d4f73 100644 --- a/spec/unit/knife/bootstrap_spec.rb +++ b/spec/unit/knife/bootstrap_spec.rb @@ -35,6 +35,8 @@ describe Chef::Knife::Bootstrap do before(:each) do Chef::Log.logger = Logger.new(StringIO.new) @knife = Chef::Knife::Bootstrap.new + # Merge default settings in. + @knife.merge_configs @knife.config[:template_file] = File.expand_path(File.join(CHEF_SPEC_DATA, "bootstrap", "test.erb")) @stdout = StringIO.new @knife.ui.stub!(:stdout).and_return(@stdout) diff --git a/spec/unit/knife/ssh_spec.rb b/spec/unit/knife/ssh_spec.rb index a4c4c33c8b..7f1ed0e321 100644 --- a/spec/unit/knife/ssh_spec.rb +++ b/spec/unit/knife/ssh_spec.rb @@ -34,6 +34,7 @@ describe Chef::Knife::Ssh do before do @knife = Chef::Knife::Ssh.new + @knife.merge_configs @knife.config[:attribute] = "fqdn" @node_foo = Chef::Node.new @node_foo.automatic_attrs[:fqdn] = "foo.example.org" diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index e8fdc38d2b..d4d721a20d 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -180,6 +180,36 @@ describe Chef::Knife do lambda {Chef::Knife.run(%w{fuuu uuuu fuuuu})}.should raise_error(SystemExit) { |e| e.status.should_not == 0 } end + describe "merging configuration options" do + before do + KnifeSpecs::TestYourself.option(:opt_with_default, + :short => "-D VALUE", + :default => "default-value") + Chef::Config[:knife] = {} + end + + it "prefers the default value if no config or command line value is present" do + knife_command = KnifeSpecs::TestYourself.new([]) #empty argv + knife_command.configure_chef + knife_command.config[:opt_with_default].should == "default-value" + end + + it "prefers a value in Chef::Config[:knife] to the default" do + Chef::Config[:knife][:opt_with_default] = "from-knife-config" + knife_command = KnifeSpecs::TestYourself.new([]) #empty argv + knife_command.configure_chef + knife_command.config[:opt_with_default].should == "from-knife-config" + end + + it "prefers a value from command line over Chef::Config and the default" do + Chef::Config[:knife][:opt_with_default] = "from-knife-config" + knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"]) + knife_command.configure_chef + knife_command.config[:opt_with_default].should == "from-cli" + end + end + + end describe "when first created" do |