Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force a default reporter for ad-hoc runners #2610

Merged
merged 2 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/inspec/base_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def self.default_options
}
end

def self.parse_reporters(opts)
def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize
# merge in any legacy formats as reporter
# this method will only be used for ad-hoc runners
if !opts['format'].nil? && opts['reporter'].nil?
Expand All @@ -102,6 +102,9 @@ def self.parse_reporters(opts)
opts.delete('format')
end

# default to cli report for ad-hoc runners
opts['reporter'] = ['cli'] if opts['reporter'].nil?

# parse out cli to proper report format
if opts['reporter'].is_a?(Array)
reports = {}
Expand Down
18 changes: 18 additions & 0 deletions test/unit/runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
Inspec::Runner.any_instance.stubs(:validate_attributes_file_readability!)
end

describe 'confirm reporter defaults to cli' do
it 'defaults to cli when format and reporter not set' do
opts = { command_runner: :generic, backend_cache: true }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { 'cli' => { 'stdout' => true } }
config['reporter'].must_equal expected
end

it 'does not default when format is set' do
opts = { command_runner: :generic, backend_cache: true, 'format' => 'json' }
runner = Inspec::Runner.new(opts)
config = runner.instance_variable_get(:"@conf")
expected = { 'json' => { 'stdout' => true } }
config['reporter'].must_equal expected
end
end

describe 'when backend caching is enabled' do
it 'returns a backend with caching' do
opts = { command_runner: :generic, backend_cache: true }
Expand Down