summaryrefslogtreecommitdiff
path: root/spec/unit/knife_spec.rb
diff options
context:
space:
mode:
authorMarc A. Paradise <marc.paradise@gmail.com>2019-05-08 16:37:36 -0400
committerMarc A. Paradise <marc.paradise@gmail.com>2019-05-08 16:55:13 -0400
commitcb3aead33cd5aebea7162f0979989efe8a789861 (patch)
treeea3d62afc08326886e5d0f87ceffee64421bb445 /spec/unit/knife_spec.rb
parentd82c20419b2288c730e0a0c3ff0ad36c2b5b4019 (diff)
downloadchef-cb3aead33cd5aebea7162f0979989efe8a789861.tar.gz
Move original config initialization to constructorKNIFE-EC2-567/handle-unmerged-case
This moves initialization of @original_config out of merge_configs and into the constructor. A common access pattern for plugins running knife commands is: cmd = KnifeCommand.new cmd.config[:something] = value cmd.run This bypasses the `Knife.run` class method, which does extra config initialization - including merge_configs. When that happens, `config_source` will now return `nil` as the source instead of exploding. 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.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb
index 6fcb831531..080b2ffa29 100644
--- a/spec/unit/knife_spec.rb
+++ b/spec/unit/knife_spec.rb
@@ -280,6 +280,31 @@ describe Chef::Knife do
expect(other_deps_loaded).to be_truthy
end
+ describe "working with unmerged configuration in #config_source" do
+ let(:command) { KnifeSpecs::TestYourself.new([]) }
+
+ before do
+ KnifeSpecs::TestYourself.option(:opt_with_default,
+ short: "-D VALUE",
+ default: "default-value")
+ end
+ # This supports a use case used by plugins, where the pattern
+ # seems to follow:
+ # cmd = KnifeCommand.new
+ # cmd.config[:config_key] = value
+ # cmd.run
+ #
+ # This bypasses Knife::run and the `merge_configs` call it
+ # performs - config_source should break when that happens.
+ context "when config is fed in directly without a merge" do
+ it "retains the value but returns nil as a config source" do
+ command.config[:test1] = "value"
+ expect(command.config[:test1]).to eq "value"
+ expect(command.config_source(:test1)).to eq nil
+ end
+ end
+
+ end
describe "merging configuration options" do
before do
KnifeSpecs::TestYourself.option(:opt_with_default,