mirror of
https://github.com/inspec/inspec
synced 2024-12-04 02:19:50 +00:00
84817366a1
* Add `release-2.0` target branch to AppVeyor/Travis (#2510) Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * simpleconfig: Remove deprecated config keys Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * cli (exec): Remove `--cache` command line argument Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * platform: Remove lowercase os name protection Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `contain_legacy_plus` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `contain_match` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `with_version` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `belong_to_group` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `belong_to_primary_group` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * matcher: Remove `contain` matcher Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * passwd: Remove deprecated properties This removes: - `passwd.count` - `passwd.username` - `passwd.usernames` - `passwd.uid` Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * auditd_rules: Remove in favor of `auditd` resource Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * cli: Remove `login_automate` command Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com> * Remove `resource_skipped` message method Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
115 lines
4.5 KiB
Ruby
115 lines
4.5 KiB
Ruby
# encoding: utf-8
|
|
|
|
# author: Jerry Aldrich
|
|
|
|
require 'helper'
|
|
require 'inspec/profile_context'
|
|
|
|
describe 'resource exception' do
|
|
let(:profile) do
|
|
profile = MockLoader.load_profile('profile-with-resource-exceptions')
|
|
profile.load_libraries
|
|
profile.collect_tests
|
|
profile
|
|
end
|
|
|
|
let(:checks) do
|
|
checks = []
|
|
profile.runner_context.rules.values.each do |rule|
|
|
checks.push(Inspec::Rule.prepare_checks(rule))
|
|
end
|
|
checks
|
|
end
|
|
|
|
describe 'within initialize' do
|
|
it 'skips resource when `Inspec::Exceptions::ResourceSkipped` is raised' do
|
|
checks[0][0][1][0].resource_skipped?.must_equal true
|
|
checks[0][0][1][0].resource_exception_message.must_equal 'Skipping because reasons'
|
|
checks[0][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
|
|
it 'fails resource when `Inspec::Exceptions::ResourceFailed` is raised' do
|
|
checks[1][0][1][0].resource_failed?.must_equal true
|
|
checks[1][0][1][0].resource_exception_message.must_equal 'Failing because reasons'
|
|
checks[1][0][1][0].resource_skipped?.must_equal false
|
|
end
|
|
|
|
it 'does not affect other tests' do
|
|
checks[2][0][1][0].resource_skipped?.must_equal false
|
|
checks[2][0][1][0].resource_failed?.must_equal false
|
|
checks[2][0][1][0].resource_exception_message.must_be_nil
|
|
end
|
|
end
|
|
|
|
describe 'within a matcher' do
|
|
it 'fails resource when `Inspec::Exceptions::ResourceFailed` is raised' do
|
|
checks[3][0][1][0].resource_failed?.must_equal true
|
|
checks[3][0][1][0].resource_exception_message.must_equal 'Failing inside matcher'
|
|
checks[3][0][1][0].resource_skipped?.must_equal false
|
|
end
|
|
|
|
it 'skips resource when `Inspec::Exceptions::ResourceSkipped` is raised' do
|
|
checks[4][0][1][0].resource_skipped?.must_equal true
|
|
checks[4][0][1][0].resource_exception_message.must_equal 'Skipping inside matcher'
|
|
checks[4][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
end
|
|
|
|
describe 'within a control' do
|
|
it 'skips resource when `Inspec::Exceptions::ResourceSkipped` is raised' do
|
|
checks[5][0][1][0].resource_skipped?.must_equal true
|
|
checks[5][0][1][0].resource_exception_message.must_equal 'Skipping because reasons'
|
|
checks[5][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
|
|
it 'fails resource when `Inspec::Exceptions::ResourceFailed` is raised' do
|
|
checks[5][1][1][0].resource_failed?.must_equal true
|
|
checks[5][1][1][0].resource_exception_message.must_equal 'Failing because reasons'
|
|
checks[5][1][1][0].resource_skipped?.must_equal false
|
|
end
|
|
end
|
|
|
|
describe 'within FilterTable' do
|
|
it 'skips resource when `Inspec::Exceptions::ResourceSkipped` is raised' do
|
|
checks[6][0][1][0].resource_skipped?.must_equal true
|
|
checks[6][0][1][0].resource_exception_message.must_equal 'Skipping inside FilterTable'
|
|
checks[6][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
|
|
it 'fails resource when `Inspec::Exceptions::ResourceFailed` is raised' do
|
|
checks[7][0][1][0].resource_failed?.must_equal true
|
|
checks[7][0][1][0].resource_exception_message.must_equal 'Failing inside FilterTable'
|
|
checks[7][0][1][0].resource_skipped?.must_equal false
|
|
end
|
|
|
|
describe 'and multiple filters are used' do
|
|
it 'skips resource when `Inspec::Exceptions::ResourceSkipped` is raised' do
|
|
checks[8][0][1][0].resource_skipped?.must_equal true
|
|
checks[8][0][1][0].resource_exception_message.must_equal 'Skipping inside FilterTable'
|
|
checks[8][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
|
|
it 'fails resource when `Inspec::Exceptions::ResourceFailed` is raised' do
|
|
checks[9][0][1][0].resource_failed?.must_equal true
|
|
checks[9][0][1][0].resource_exception_message.must_equal 'Failing inside FilterTable'
|
|
checks[9][0][1][0].resource_skipped?.must_equal false
|
|
end
|
|
|
|
it 'does not halt the run/fail all tests when an incorrect filter is used' do
|
|
checks[10][0][1][0].resource_skipped?.must_equal true
|
|
checks[10][0][1][0].resource_exception_message.must_equal 'Skipping inside FilterTable'
|
|
checks[10][0][1][0].resource_failed?.must_equal false
|
|
end
|
|
|
|
it 'does not halt the run/fail all tests when an incorrect filter is used' do
|
|
checks[11][0][1][0].resource_failed?.must_equal true
|
|
checks[11][0][1][0].resource_exception_message.must_equal 'Failing inside FilterTable'
|
|
checks[11][0][1][0].resource_skipped?.must_equal false
|
|
end
|
|
end
|
|
|
|
it 'does not affect regular FilterTable usage' do
|
|
checks[12][0][1][0].another_filter.must_equal ['example']
|
|
end
|
|
end
|
|
end
|