mirror of
https://github.com/inspec/inspec
synced 2025-02-17 06:28:40 +00:00
Prevent logs from showing up when running inspec json (#3391)
* Prevent logs from showing up when running inspec json. * Update it test text. Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
parent
9cb3b1e7dd
commit
527571750d
4 changed files with 30 additions and 1 deletions
|
@ -35,6 +35,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
|||
def json(target)
|
||||
o = opts.dup
|
||||
diagnose(o)
|
||||
o['log_location'] = STDERR
|
||||
configure_logger(o)
|
||||
|
||||
o[:backend] = Inspec::Backend.create(target: 'mock://')
|
||||
o[:check_mode] = true
|
||||
o[:vendor_cache] = Inspec::Cache.new(o[:vendor_cache])
|
||||
|
|
|
@ -135,7 +135,6 @@ describe 'inspec json' do
|
|||
|
||||
it 'can execute a profile inheritance' do
|
||||
out = inspec('json ' + profile)
|
||||
out.stderr.must_equal ''
|
||||
out.exit_status.must_equal 0
|
||||
JSON.load(out.stdout).must_be_kind_of Hash
|
||||
end
|
||||
|
@ -149,6 +148,14 @@ describe 'inspec json' do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'inspec json does not write logs to STDOUT' do
|
||||
it 'can execute a profile with warn calls and parse STDOUT as valid JSON' do
|
||||
out = inspec('json ' + File.join(profile_path, 'warn_logs'))
|
||||
out.exit_status.must_equal 0
|
||||
JSON.load(out.stdout)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'inspec json with a profile containing only_if' do
|
||||
it 'ignores the `only_if`' do
|
||||
out = inspec('json ' + File.join(profile_path, 'only-if-os-nope'))
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
Inspec::Log.warn 'This is a warn call!'
|
||||
Inspec::Log.warn 'This is another warn call!'
|
||||
|
||||
control 'tmp-1.0' do # A unique ID for this control
|
||||
impact 0.7 # The criticality, if this control fails.
|
||||
title 'Create /tmp directory' # A human-readable title
|
||||
desc 'An optional description...'
|
||||
describe file('/tmp') do # The actual test
|
||||
it { should be_directory }
|
||||
end
|
||||
end
|
8
test/unit/mock/profiles/warn_logs/inspec.yml
Normal file
8
test/unit/mock/profiles/warn_logs/inspec.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
name: warn_logs
|
||||
title: InSpec Profile
|
||||
maintainer: The Authors
|
||||
copyright: The Authors
|
||||
copyright_email: you@example.com
|
||||
license: Apache-2.0
|
||||
summary: An InSpec Compliance Profile
|
||||
version: 0.1.0
|
Loading…
Add table
Reference in a new issue