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

View file

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