diff options
author | danielsdeleo <dan@chef.io> | 2016-10-18 15:39:15 -0700 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2016-10-18 16:13:14 -0700 |
commit | 466bfbf2db3c02c0f5263f0e93e12baf1de69832 (patch) | |
tree | fe21e3d81554bcfb30b50033ab9d5921f69c5355 /spec/unit/knife_spec.rb | |
parent | 488dc6137ec3ce77e35ffd865fb1758c8403ad09 (diff) | |
download | chef-466bfbf2db3c02c0f5263f0e93e12baf1de69832.tar.gz |
Implement `--config-option` CLI opt for knifedan/config-option-in-knife
The `--config-option` CLI option allows setting any `Chef::Config`
setting on the command line, which allows applications to be used
without a configuration file even if a desired config option does not
have a corresponding CLI option. This CLI option was present in the help
output for knife but was not actually implemented. Moving the behavior
into chef-config allows us to use it for both `chef-client` and `knife`.
Signed-off-by: Daniel DeLeo <dan@chef.io>
Diffstat (limited to 'spec/unit/knife_spec.rb')
-rw-r--r-- | spec/unit/knife_spec.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/unit/knife_spec.rb b/spec/unit/knife_spec.rb index f0ec45d59a..9569526b2a 100644 --- a/spec/unit/knife_spec.rb +++ b/spec/unit/knife_spec.rb @@ -349,6 +349,37 @@ describe Chef::Knife do expect { knife.run_with_pretty_exceptions }.to raise_error(Exception) end end + + describe "setting arbitrary configuration with --config-option" do + + let(:stdout) { StringIO.new } + + let(:stderr) { StringIO.new } + + let(:stdin) { StringIO.new } + + let(:ui) { Chef::Knife::UI.new(stdout, stderr, stdin, disable_editing: true) } + + let(:subcommand) do + KnifeSpecs::TestYourself.options = Chef::Application::Knife.options.merge(KnifeSpecs::TestYourself.options) + KnifeSpecs::TestYourself.new(%w{--config-option badly_formatted_arg}).tap do |cmd| + cmd.ui = ui + end + end + + it "sets arbitrary configuration via --config-option" do + Chef::Knife.run(%w{test yourself --config-option arbitrary_config_thing=hello}, Chef::Application::Knife.options) + expect(Chef::Config[:arbitrary_config_thing]).to eq("hello") + end + + it "handles errors in arbitrary configuration" do + expect(subcommand).to receive(:exit).with(1) + subcommand.configure_chef + expect(stderr.string).to include("ERROR: Unparsable config option \"badly_formatted_arg\"") + expect(stdout.string).to include(subcommand.opt_parser.to_s) + end + end + end describe "when first created" do |