Added plumbing logic to integrate enhanced outcomes in run_data

Signed-off-by: Nikita Mathur <nikita.mathur@chef.io>
This commit is contained in:
Nikita Mathur 2022-06-17 17:28:11 +05:30
parent 4b7543d109
commit 29cd28f6ac
2 changed files with 15 additions and 2 deletions

View file

@ -6,7 +6,7 @@ module Inspec::Formatters
class Base < RSpec::Core::Formatters::BaseFormatter
RSpec::Core::Formatters.register self, :close, :dump_summary, :stop
attr_accessor :backend, :run_data
attr_accessor :backend, :run_data, :enhanced_outcomes
def initialize(output)
super(output)
@ -17,6 +17,7 @@ module Inspec::Formatters
@backend = nil
@all_controls_count = nil
@control_checks_count_map = {}
@enhanced_outcomes = nil
end
# RSpec Override: #dump_summary
@ -50,7 +51,6 @@ module Inspec::Formatters
else
hash[:message] = exception_message(e)
end
next if e.is_a? RSpec::Expectations::ExpectationNotMetError
hash[:exception] = e.class.name
@ -68,6 +68,8 @@ module Inspec::Formatters
# flesh out the profiles key with additional profile information
run_data[:profiles] = profiles_info
add_enhanced_outcomes_to_controls if enhanced_outcomes
# add the platform information for this particular target
run_data[:platform] = {
name: platform(:name),
@ -110,6 +112,16 @@ module Inspec::Formatters
private
def add_enhanced_outcomes_to_controls
all_unique_controls.each do |control|
control[:status] = determine_control_enhanced_outcome(control)
end
end
def determine_control_enhanced_outcome(control)
# logic to find enhanced_outcome status
end
def all_unique_controls
unique_controls = Set.new
run_data[:profiles].each do |profile|

View file

@ -196,6 +196,7 @@ module Inspec
def configure_output
RSpec.configuration.output_stream = $stdout
@formatter = RSpec.configuration.add_formatter(Inspec::Formatters::Base)
@formatter.enhanced_outcomes = @conf.final_options["enhanced_outcomes"]
RSpec.configuration.add_formatter(Inspec::Formatters::ShowProgress, $stderr) if @conf[:show_progress]
set_optional_formatters
RSpec.configuration.color = @conf["color"]