Added failure and passed conditions in enhanced_outcomes

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2022-06-24 16:04:10 +05:30
parent 4e83f395c8
commit 9d531b68de
2 changed files with 21 additions and 10 deletions

View file

@ -120,14 +120,16 @@ module Inspec::Formatters
def determine_control_enhanced_outcome(control)
if control_has_error(control)
return { name: "Error", abbrev: "ERR" }
{ name: "Error", abbrev: "ERR" }
elsif control[:impact].to_f == 0.0
return { name: "Not Applicable", abbrev: "N/A" }
{ name: "Not Applicable", abbrev: "N/A" }
elsif control_has_all_tests_skipped(control)
return { name: "Not Reviewed", abbrev: "N/R" }
{ name: "Not Reviewed", abbrev: "N/R" }
elsif control[:results].any? { |r| r[:status] == "failed" }
{ name: "Failed", abbrev: "fail"}
else
{ name: "Passed", abbrev: "pass"}
end
{}
end
def control_has_all_tests_skipped(control)

View file

@ -56,15 +56,17 @@ module Inspec::Plugin::V2::PluginType
end
def add_enhanced_outcomes(control_id)
enhanced_outcomes = {}
if control_has_error(@notifications[control_id])
enhanced_outcomes = { name: "Error", abbrev: "ERR" }
{ name: "Error", abbrev: "ERR" }
elsif control_has_impact_zero(@notifications[control_id])
enhanced_outcomes = { name: "Not Applicable", abbrev: "N/A" }
{ name: "Not Applicable", abbrev: "N/A" }
elsif control_has_all_tests_skipped(@notifications[control_id])
enhanced_outcomes = { name: "Not Reviewed", abbrev: "N/R" }
{ name: "Not Reviewed", abbrev: "N/R" }
elsif control_has_any_tests_failed(@notifications[control_id])
{ name: "Failed", abbrev: "fail" }
else
{ name: "Passed", abbrev: "pass" }
end
enhanced_outcomes
end
def control_has_error(notifications)
@ -81,6 +83,13 @@ module Inspec::Plugin::V2::PluginType
end
end
def control_has_any_tests_failed(notifications)
notifications.any? do |notification_data|
_notification, status = notification_data
status == "failed"
end
end
def control_has_impact_zero(notifications)
notification_data = notifications.first
notification_impact = notification_data.first.example.metadata[:impact]