2017-05-05 13:04:02 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# copyright: 2017, Chef Software Inc.
|
|
|
|
|
|
|
|
require 'helper'
|
2019-02-26 02:05:18 +00:00
|
|
|
require 'inspec/secrets'
|
2017-05-05 13:04:02 +00:00
|
|
|
|
|
|
|
describe Inspec::Runner do
|
2019-02-26 02:05:18 +00:00
|
|
|
let(:runner) { Inspec::Runner.new({ command_runner: :generic }) }
|
|
|
|
|
|
|
|
# =============================================================== #
|
|
|
|
# Reporter Options
|
|
|
|
# =============================================================== #
|
|
|
|
|
|
|
|
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
|
2018-10-24 19:08:07 +00:00
|
|
|
end
|
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
it 'does not default when format is set' do
|
|
|
|
opts = { command_runner: :generic, backend_cache: true, 'reporter' => ['json'] }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
config = runner.instance_variable_get(:"@conf")
|
|
|
|
expected = { 'json' => { 'stdout' => true } }
|
|
|
|
config['reporter'].must_equal expected
|
2017-12-04 21:40:14 +00:00
|
|
|
end
|
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
it 'delets format if set to a rspec format' do
|
|
|
|
opts = { command_runner: :generic, backend_cache: true, 'reporter' => ['progress'] }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
config = runner.instance_variable_get(:"@conf")
|
|
|
|
config['reporter'].must_equal Hash.new
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
# =============================================================== #
|
|
|
|
# Exit Codes
|
|
|
|
# =============================================================== #
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
describe 'testing runner.run exit codes' do
|
|
|
|
it 'returns proper exit code when no profile is added' do
|
|
|
|
proc { runner.run.must_equal 0 }
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
# =============================================================== #
|
|
|
|
# Backend Caching
|
|
|
|
# =============================================================== #
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
describe 'when backend caching is enabled' do
|
|
|
|
it 'returns a backend with caching' do
|
|
|
|
opts = { command_runner: :generic, backend_cache: true }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
backend = runner.instance_variable_get(:@backend)
|
|
|
|
backend.backend.cache_enabled?(:command).must_equal true
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
2019-02-26 02:05:18 +00:00
|
|
|
end
|
2017-05-05 13:04:02 +00:00
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
describe 'when backend caching is disabled' do
|
|
|
|
it 'returns a backend without caching' do
|
|
|
|
opts = { command_runner: :generic, backend_cache: false }
|
|
|
|
runner = Inspec::Runner.new(opts)
|
|
|
|
backend = runner.instance_variable_get(:@backend)
|
|
|
|
backend.backend.cache_enabled?(:command).must_equal false
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
|
|
|
|
2019-02-26 02:05:18 +00:00
|
|
|
it 'returns a backend without caching as default' do
|
|
|
|
backend = runner.instance_variable_get(:@backend)
|
|
|
|
backend.backend.cache_enabled?(:command).must_equal false
|
2017-05-05 13:04:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|