mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
Added impact setting option in only_if
Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
parent
7cbaa892cc
commit
84c14a505a
3 changed files with 31 additions and 5 deletions
|
@ -16,6 +16,7 @@ module Inspec
|
|||
attr_reader :__waiver_data
|
||||
attr_accessor :resource_dsl
|
||||
attr_reader :__profile_id
|
||||
attr_accessor :impact
|
||||
|
||||
def initialize(id, profile_id, resource_dsl, opts, &block)
|
||||
@impact = nil
|
||||
|
@ -133,10 +134,11 @@ module Inspec
|
|||
#
|
||||
# @param [Type] &block returns true if tests are added, false otherwise
|
||||
# @return [nil]
|
||||
def only_if(message = nil)
|
||||
def only_if(message = nil, impact: nil)
|
||||
return unless block_given?
|
||||
return if @__skip_only_if_eval == true
|
||||
|
||||
self.impact = impact if impact && !yield
|
||||
@__skip_rule[:result] ||= !yield
|
||||
@__skip_rule[:type] = :only_if
|
||||
@__skip_rule[:message] = message
|
||||
|
|
|
@ -60,3 +60,19 @@ control "tmp-5.0" do
|
|||
it { should cmp "e.1" }
|
||||
end
|
||||
end
|
||||
|
||||
# Example of setting impact using code and marking it N/A
|
||||
control "tmp-6.0.1" do
|
||||
only_if(impact: 0.0) { false }
|
||||
describe file("/tmp") do
|
||||
it { should be_directory }
|
||||
end
|
||||
end
|
||||
|
||||
# Example of setting impact using code and not marked as N/A
|
||||
control "tmp-6.0.2" do
|
||||
only_if(impact: 0.5) { false }
|
||||
describe file("/tmp") do
|
||||
it { should be_directory }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1340,14 +1340,14 @@ EOT
|
|||
end
|
||||
|
||||
it "should show enhanced_outcomes for skipped tests in controls" do
|
||||
_(run_result.stdout).must_include "3 skipped"
|
||||
_(run_result.stdout).must_include "2 controls not reviewed"
|
||||
_(run_result.stdout).must_include "5 skipped"
|
||||
_(run_result.stdout).must_include "3 controls not reviewed"
|
||||
_(run_result.stdout).must_include "N/R"
|
||||
end
|
||||
|
||||
it "should show enhanced_outcomes for controls with impact 0" do
|
||||
_(run_result.stdout).must_include "3 skipped"
|
||||
_(run_result.stdout).must_include "2 controls not applicable"
|
||||
_(run_result.stdout).must_include "5 skipped"
|
||||
_(run_result.stdout).must_include "3 controls not applicable"
|
||||
_(run_result.stdout).must_include "N/A"
|
||||
end
|
||||
|
||||
|
@ -1364,6 +1364,14 @@ EOT
|
|||
it "should show enhanced_outcomes for passed controls" do
|
||||
_(run_result.stdout).must_include "1 successful control"
|
||||
end
|
||||
|
||||
it "should mark control as N/A using zero impact from only_if" do
|
||||
_(run_result.stdout).must_include "N/A tmp-6.0.1"
|
||||
end
|
||||
|
||||
it "should not mark control as N/A using non-zeo impact from only_if" do
|
||||
_(run_result.stdout).must_include "N/R tmp-6.0.2"
|
||||
end
|
||||
end
|
||||
|
||||
describe "when running profile with enhanced_outcomes option and yaml reporter" do
|
||||
|
|
Loading…
Reference in a new issue