fix inherited profile cli report

This commit is contained in:
Victoria Jeffrey 2016-09-01 18:54:03 -04:00 committed by Christoph Hartmann
parent f418e873df
commit 99ce09c4ac
7 changed files with 67 additions and 3 deletions

View file

@ -166,7 +166,13 @@ class InspecRspecJson < InspecRspecMiniJson
def example2control(example, profiles)
profile = profiles[example[:profile_id]]
return nil if profile.nil? || profile[:controls].nil?
# if this is an inherited profile, the profile comes in as
# nil, so we need do dig deep to get our control
if profile.nil? || profile[:controls].nil?
profiles.each do |x|
return x[1][:controls][example[:id]]
end
end
profile[:controls][example[:id]]
end

View file

@ -23,6 +23,7 @@ module FunctionalHelper
let(:example_control) { File.join(example_profile, 'controls', 'example.rb') }
let(:inheritance_profile) { File.join(examples_path, 'profile') }
let(:failure_control) { File.join(profile_path, 'failures', 'controls', 'failures.rb') }
let(:simple_inheritance) { File.join(profile_path, 'simple-inheritance') }
let(:dst) {
# create a temporary path, but we only want an auto-clean helper

View file

@ -147,4 +147,15 @@ Summary: \e[32m2 successful\e[0m, \e[31m0 failures\e[0m, \e[37m0 skipped\e[0m
out.stdout.must_include "undefined method `should_nota' "
end
end
describe 'given an inherited profile that has more that one test per control block' do
let(:out) { inspec('exec ' + simple_inheritance) }
it 'should print all the results' do
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ tmp-1.0: Create /tmp directory (1 failed)\e[0m"
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ should not be directory\e[0m"
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ undefined method `should_nota'"
out.stdout.force_encoding(Encoding::UTF_8).must_include "✖ expected `File /tmp.directory?` to return false, got true\e[0m"
end
end
end

View file

@ -2,10 +2,31 @@
# copyright: 2015, Chef Software, Inc.
# license: All rights reserved
title '/tmp profile'
title 'failures /tmp profile'
# you can also use plain tests
# control, first test passes, second fails
control "tmp-1.0" do # A unique ID for this control
impact 0.7 # The criticality, if this control fails.
title "Create /tmp directory" # A human-readable title
desc "An optional description..." # Describe why this is needed
tag data: "temp data" # A tag allows you to associate key information
tag "security" # to the test
ref "Document A-12", url: 'http://...' # Additional references
describe file('/tmp') do # The actual test
it { should be_directory }
it { should_not be_directory }
end
end
# anonymous describe block, first passes, second is syntax error
describe file('/tmp') do
it { should be_directory }
it { should_nota be_directory }
end
# anonymous describe block, first fails, second passes
describe file('/tmp') do
it { should_not be_directory }
it { should be_directory }
end

View file

@ -0,0 +1,8 @@
name: failures
title: InSpec Profile
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: All Rights Reserved
summary: An InSpec Compliance Profile
version: 0.1.0

View file

@ -0,0 +1,7 @@
# encoding: utf-8
include_controls 'failures'
describe file('/tmp') do
it { should be_directory }
end

View file

@ -0,0 +1,10 @@
name: simple inheritance
title: InSpec example simple inheritance
maintainer: Chef Software, Inc.
copyright: Chef Software, Inc.
copyright_email: support@chef.io
license: Apache 2 license
version: 1.0.0
depends:
- name: failures
path: ../failures