2017-12-06 21:22:11 +00:00
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
|
|
|
require 'helper'
|
|
|
|
require 'thor'
|
|
|
|
|
|
|
|
describe 'BaseCLI' do
|
|
|
|
let(:cli) { Inspec::BaseCLI.new }
|
|
|
|
|
2019-01-28 01:07:32 +00:00
|
|
|
describe 'formats the platfrom information' do
|
|
|
|
it 'verify platform formatting' do
|
2018-02-20 12:37:23 +00:00
|
|
|
hash = { name: 'test-os', families: 'aws, cloud', release: 'aws-sdk-v1' }
|
|
|
|
expect = <<EOF
|
|
|
|
Name: \e[1m\e[35mtest-os\e[0m
|
|
|
|
Families: \e[1m\e[35maws, cloud\e[0m
|
|
|
|
Release: \e[1m\e[35maws-sdk-v1\e[0m
|
|
|
|
EOF
|
2019-01-28 01:07:32 +00:00
|
|
|
_(Inspec::BaseCLI.format_platform_info(params: hash, indent: 2, color: 35)).must_equal expect
|
2018-02-09 16:46:09 +00:00
|
|
|
end
|
2017-12-06 21:22:11 +00:00
|
|
|
end
|
2018-02-08 09:06:58 +00:00
|
|
|
|
2018-02-09 14:14:40 +00:00
|
|
|
describe 'configure_logger' do
|
2019-05-18 00:41:19 +00:00
|
|
|
after do
|
|
|
|
Inspec::Log.init
|
|
|
|
Inspec::Log.level = :fatal
|
|
|
|
end
|
|
|
|
|
2018-02-09 14:14:40 +00:00
|
|
|
let(:options) do
|
|
|
|
o = {
|
|
|
|
'log_location' => STDERR,
|
|
|
|
'log_level' => 'debug',
|
2018-02-09 16:19:52 +00:00
|
|
|
'reporter' => {
|
|
|
|
'json' => {
|
|
|
|
'stdout' => true,
|
|
|
|
},
|
|
|
|
},
|
2018-02-09 14:14:40 +00:00
|
|
|
}
|
|
|
|
Thor::CoreExt::HashWithIndifferentAccess.new(o)
|
|
|
|
end
|
2018-02-09 16:19:52 +00:00
|
|
|
let(:format) do
|
|
|
|
device = options[:logger].instance_variable_get(:"@logdev")
|
|
|
|
device.instance_variable_get(:"@dev")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets to stderr for log_location' do
|
|
|
|
cli.send(:configure_logger, options)
|
|
|
|
format.must_equal STDERR
|
|
|
|
end
|
2018-02-09 14:14:40 +00:00
|
|
|
|
2018-02-09 16:46:09 +00:00
|
|
|
it 'sets to stderr for json' do
|
2018-02-09 16:19:52 +00:00
|
|
|
options.delete('log_location')
|
|
|
|
options.delete('log_level')
|
|
|
|
cli.send(:configure_logger, options)
|
2018-02-09 16:46:09 +00:00
|
|
|
format.must_equal STDERR
|
2018-02-09 16:19:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'sets defaults to stdout for everything else' do
|
|
|
|
options.delete('log_location')
|
|
|
|
options.delete('log_level')
|
|
|
|
options.delete('reporter')
|
|
|
|
|
2018-02-09 14:14:40 +00:00
|
|
|
cli.send(:configure_logger, options)
|
2018-02-09 16:19:52 +00:00
|
|
|
format.must_equal STDOUT
|
2018-02-09 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-08 09:06:58 +00:00
|
|
|
|
|
|
|
describe 'suppress_log_output?' do
|
|
|
|
it 'suppresses json' do
|
|
|
|
opts = { 'reporter' => { 'json' => { 'stdout' => true }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'do not suppresses json-min when going to file' do
|
|
|
|
opts = { 'reporter' => { 'json-min' => { 'file' => '/tmp/json' }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'suppresses json-rspec' do
|
|
|
|
opts = { 'reporter' => { 'json-rspec' => { 'stdout' => true }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal true
|
|
|
|
end
|
|
|
|
|
2018-08-23 17:43:48 +00:00
|
|
|
it 'suppresses json-automate' do
|
|
|
|
opts = { 'reporter' => { 'json-automate' => { 'stdout' => true }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal true
|
|
|
|
end
|
|
|
|
|
2018-02-08 09:06:58 +00:00
|
|
|
it 'suppresses junit' do
|
|
|
|
opts = { 'reporter' => { 'junit' => { 'stdout' => true }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'do not suppresses cli' do
|
|
|
|
opts = { 'reporter' => { 'cli' => nil } }
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'do not suppresses cli' do
|
|
|
|
opts = { 'reporter' => { 'cli' => nil, 'json' => {'file' => '/tmp/json' }}}
|
|
|
|
cli.send(:suppress_log_output?, opts).must_equal false
|
|
|
|
end
|
|
|
|
end
|
2017-12-06 21:22:11 +00:00
|
|
|
end
|