mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
Remove conditional checks for true and reverse if conditional on
Inline if_false_message into test. Signed-off-by: Miah Johnson <miah@chia-pet.org>
This commit is contained in:
parent
782be81807
commit
e710b5b633
2 changed files with 9 additions and 9 deletions
|
@ -184,18 +184,18 @@ module Inspec
|
|||
end
|
||||
|
||||
def self.prepare_checks(rule)
|
||||
msg = skip_status(rule)
|
||||
return checks(rule) unless msg[:result].eql?(true)
|
||||
if msg[:result].eql?(true) && msg[:message].nil?
|
||||
msg = 'Skipped control due to only_if condition.'
|
||||
skip_check = skip_status(rule)
|
||||
return checks(rule) unless skip_check[:result].eql?(true)
|
||||
if skip_check[:message]
|
||||
skip_check = "Skipped control due to only_if condition: #{skip_check[:message]}"
|
||||
else
|
||||
msg = "Skipped control due to only_if condition: #{msg[:message]}"
|
||||
skip_check = 'Skipped control due to only_if condition.'
|
||||
end
|
||||
|
||||
# TODO: we use os as the carrier here, but should consider
|
||||
# a separate resource to do skipping
|
||||
resource = rule.os
|
||||
resource.skip_resource(msg)
|
||||
resource.skip_resource(skip_check)
|
||||
[['describe', [resource], nil]]
|
||||
end
|
||||
|
||||
|
|
|
@ -117,7 +117,6 @@ describe Inspec::ProfileContext do
|
|||
describe 'global only_if' do
|
||||
let(:if_true) { "only_if { true }\n" }
|
||||
let(:if_false) { "only_if { false }\n" }
|
||||
let(:if_false_message) { "only_if('if_false_message skipped') { false }\n" }
|
||||
let(:describe) { "describe nil do its(:to_i) { should eq rand } end\n" }
|
||||
let(:control) { "control 1 do\n#{describe}\nend\n" }
|
||||
let(:control_2) { "control 2 do\n#{describe}\nend\n" }
|
||||
|
@ -182,10 +181,11 @@ describe Inspec::ProfileContext do
|
|||
end
|
||||
|
||||
it 'allows specifying a message with true only_if' do
|
||||
profile.load(if_false_message + control)
|
||||
profile.load("only_if('this is a only_if skipped message') { false }\n" + control)
|
||||
get_checks.length.must_equal 1
|
||||
get_checks[0][1][0].resource_skipped?.must_equal true
|
||||
get_checks[0][1][0].resource_exception_message.must_equal 'Skipped control due to only_if condition: if_false_message skipped'
|
||||
get_checks[0][1][0].resource_exception_message.must_equal 'Skipped' \
|
||||
' control due to only_if condition: this is a only_if skipped message'
|
||||
get_checks[0][1][0].resource_failed?.must_equal false
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue