2017-12-06 21:22:11 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
require 'thor'
|
|
|
|
|
|
|
|
describe 'BaseCLI' do
|
|
|
|
let(:cli) { Inspec::BaseCLI.new }
|
|
|
|
|
|
|
|
describe 'merge_options' do
|
|
|
|
it 'cli defaults populate correctly' do
|
2017-12-07 12:19:36 +00:00
|
|
|
default_options = { exec: { format: 'json', backend_cache: false }}
|
2017-12-06 21:22:11 +00:00
|
|
|
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
|
|
|
|
|
2017-12-07 12:19:36 +00:00
|
|
|
opts = cli.send(:merged_opts, :exec)
|
2017-12-06 21:22:11 +00:00
|
|
|
expected = { 'format' => 'json', 'backend_cache' => false }
|
|
|
|
opts.must_equal expected
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'json-config options override cli defaults' do
|
2017-12-07 12:19:36 +00:00
|
|
|
default_options = { exec: { format: 'json', backend_cache: false }}
|
2017-12-06 21:22:11 +00:00
|
|
|
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
|
|
|
|
|
|
|
|
parsed_json = { 'backend_cache' => true }
|
|
|
|
cli.expects(:options_json).returns(parsed_json)
|
|
|
|
|
2017-12-07 12:19:36 +00:00
|
|
|
opts = cli.send(:merged_opts, :exec)
|
2017-12-06 21:22:11 +00:00
|
|
|
expected = { 'format' => 'json', 'backend_cache' => true }
|
|
|
|
opts.must_equal expected
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'cli options override json-config and default' do
|
2017-12-07 12:19:36 +00:00
|
|
|
default_options = { exec: { format: 'json', backend_cache: false }}
|
2017-12-06 21:22:11 +00:00
|
|
|
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
|
|
|
|
|
|
|
|
parsed_json = { 'backend_cache' => false }
|
|
|
|
cli.expects(:options_json).returns(parsed_json)
|
|
|
|
|
|
|
|
cli_options = { 'backend_cache' => true }
|
|
|
|
cli.instance_variable_set(:@options, cli_options)
|
|
|
|
|
2017-12-07 12:19:36 +00:00
|
|
|
opts = cli.send(:merged_opts, :exec)
|
2017-12-06 21:22:11 +00:00
|
|
|
expected = { 'format' => 'json', 'backend_cache' => true }
|
|
|
|
opts.must_equal expected
|
|
|
|
end
|
2017-12-07 12:19:36 +00:00
|
|
|
|
|
|
|
it 'make sure shell does not get exec defaults' do
|
|
|
|
default_options = { exec: { format: 'json', backend_cache: false }}
|
|
|
|
Inspec::BaseCLI.stubs(:default_options).returns(default_options)
|
|
|
|
|
|
|
|
opts = cli.send(:merged_opts)
|
|
|
|
expected = {}
|
|
|
|
opts.must_equal expected
|
|
|
|
end
|
2017-12-06 21:22:11 +00:00
|
|
|
end
|
|
|
|
end
|