diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2019-04-08 11:10:56 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2019-04-24 13:25:58 -0400 |
commit | 958cfd999370387f6b7debd7bd725b2da27832bc (patch) | |
tree | 16fcff249c6647307cbad222c9d7a9abdd7feea3 /spec/unit/knife_spec.rb | |
parent | a31851492fb2cd8d03d57fa774283cb8b6d0b102 (diff) | |
download | chef-958cfd999370387f6b7debd7bd725b2da27832bc.tar.gz |
Add Knife#config_source(key)
Subclasses can use this to determine where a given
key has received its value from.
This allows subclasses to handle deprecated CLI options
that may still be valid in Chef config by determining
if the option was provided on the CLI or via Chef::Config
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
Diffstat (limited to 'spec/unit/knife_spec.rb')
-rw-r--r-- | spec/unit/knife_spec.rb | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index ff89bc6f30..f48ab4019c 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -299,7 +299,7 @@ describe Chef::Knife do expect(Chef::Config[:log_level]).to eql(:warn) end - it "prefers the default value if no config or command line value is present" do + it "prefers the default value if no config or command line value is present and reports the source as default" do knife_command = KnifeSpecs::TestYourself.new([]) # empty argv knife_command.configure_chef expect(knife_command.config[:opt_with_default]).to eq("default-value") @@ -310,18 +310,32 @@ describe Chef::Knife do knife_command = KnifeSpecs::TestYourself.new([]) # empty argv knife_command.configure_chef expect(knife_command.config[:opt_with_default]).to eq("from-knife-config") + expect(knife_command.config_source(:opt_with_default)).to eq (:config) end - it "prefers a value from command line over Chef::Config and the default" do + it "correctly reports Chef::Config as the source when a a config entry comes from there" do Chef::Config[:knife][:opt_with_default] = "from-knife-config" + knife_command = KnifeSpecs::TestYourself.new([]) # empty argv + knife_command.configure_chef + expect(knife_command.config_source(:opt_with_default)).to eq (:config) + end + + it "prefers a value from command line over Chef::Config and the default and reports the source as CLI" do knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"]) knife_command.configure_chef expect(knife_command.config[:opt_with_default]).to eq("from-cli") + expect(knife_command.config_source(:opt_with_default)).to eq (:cli) + end + it "correctly reports CLI as the source when a config entry comes from the CLI" do + knife_command = KnifeSpecs::TestYourself.new(["-D", "from-cli"]) + knife_command.configure_chef + expect(knife_command.config_source(:opt_with_default)).to eq (:cli) end it "merges `listen` config to Chef::Config" do - Chef::Knife.run(%w{test yourself --no-listen}, Chef::Application::Knife.options) + knife_command = Chef::Knife.run(%w{test yourself --no-listen}, Chef::Application::Knife.options) expect(Chef::Config[:listen]).to be(false) + expect(knife_command.config_source(:listen)).to eq(:cli) end context "verbosity is one" do |