mirror of
https://github.com/inspec/inspec
synced 2025-03-03 06:47:22 +00:00
* Allow skipping/failing resources in FilterTable `FilterTable` is commonly used in the class body of a resource and is evaluated during an `instance_eval`. This means that if you raise an exception (e.g. SkipResource) it will halt `inspec exec` and `inspec check`. This adds an `ExceptionCatcher` class that will postpone evaluation until test execution. This allows `inspec check` and `inspec exec` to perform as intended when skipping/failing a resource in `FilterTable` Huge thanks to @adamleff for providing the starting code/ideas! Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Comment why `ExceptionCatcher` doesn't raise Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Remove `accessor` from `ExceptionCatcher` Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Return the existing ExceptionCatcher object rather than creating new Signed-off-by: Adam Leff <adam@leff.co>
32 lines
977 B
Ruby
32 lines
977 B
Ruby
# encoding: utf-8
|
|
# author: Dominik Richter
|
|
# author: Christoph Hartmann
|
|
|
|
require 'functional/helper'
|
|
require 'jsonschema'
|
|
|
|
describe 'inspec check' do
|
|
include FunctionalHelper
|
|
|
|
describe 'inspec check with json formatter' do
|
|
it 'can check a profile and produce valid JSON' do
|
|
out = inspec('check ' + integration_test_path + ' --format json')
|
|
out.exit_status.must_equal 0
|
|
JSON.parse(out.stdout)
|
|
end
|
|
end
|
|
|
|
describe 'inspec check with special characters in path' do
|
|
it 'can check a profile with special characters in its path' do
|
|
out = inspec('check ' + File.join(profile_path, '{{special-path}}'))
|
|
out.exit_status.must_equal 0
|
|
end
|
|
end
|
|
|
|
describe 'inspec check with skipping/failing a resource in FilterTable' do
|
|
it 'can check a profile with special characters in its path' do
|
|
out = inspec('check ' + File.join(profile_path, 'profile-with-resource-exceptions'))
|
|
out.exit_status.must_equal 0
|
|
end
|
|
end
|
|
end
|