mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
Make sure we have a proper exit code and report data. (#2747)
Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
parent
8079bde6eb
commit
62cb6bb846
3 changed files with 26 additions and 2 deletions
|
@ -129,8 +129,9 @@ module Inspec
|
|||
end
|
||||
|
||||
def run_tests(with = nil)
|
||||
run_data = @test_collector.run(with)
|
||||
render_output(run_data)
|
||||
@run_data = @test_collector.run(with)
|
||||
# dont output anything if we want a report
|
||||
render_output(@run_data) unless @conf['report']
|
||||
@test_collector.exit_code
|
||||
end
|
||||
|
||||
|
|
|
@ -82,6 +82,7 @@ module Inspec
|
|||
#
|
||||
# @return [int] exit code
|
||||
def exit_code
|
||||
return @rspec_exit_code if @formatter.results.empty?
|
||||
stats = @formatter.results[:statistics][:controls]
|
||||
if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0
|
||||
0
|
||||
|
|
22
test/functional/inspec_report_test.rb
Normal file
22
test/functional/inspec_report_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'functional/helper'
|
||||
|
||||
describe 'inspec report tests' do
|
||||
include FunctionalHelper
|
||||
|
||||
describe 'report' do
|
||||
it 'loads a json report' do
|
||||
o = { 'reporter' => ['json'], 'report' => true }
|
||||
runner = ::Inspec::Runner.new(o)
|
||||
runner.add_target(example_profile)
|
||||
runner.run
|
||||
runner.report.count.must_equal 4
|
||||
runner.report.inspect.must_include ':title=>"InSpec Example Profile"'
|
||||
runner.report.inspect.must_include ':status=>"passed"'
|
||||
end
|
||||
|
||||
# Due to the way we require/use rspec, you can only run one runner.
|
||||
# You have to reload rspec to run another.
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue