mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
skip profiles if the platform isnt supported
This commit is contained in:
parent
a1188b26ce
commit
14995534cd
5 changed files with 31 additions and 1 deletions
|
@ -53,6 +53,13 @@ module Inspec
|
|||
end
|
||||
|
||||
def add_profile(profile, options = {})
|
||||
# skip if not supported on this platform
|
||||
if !profile.metadata.nil? && !profile.metadata.supports_runtime?
|
||||
fail 'This profile requires InSpec version '\
|
||||
"#{profile.metadata.inspec_requirement}. You are running "\
|
||||
"InSpec v#{Inspec::VERSION}.\n"
|
||||
end
|
||||
|
||||
@test_collector.add_profile(profile)
|
||||
options[:metadata] = profile.metadata
|
||||
|
||||
|
|
|
@ -69,7 +69,8 @@ module Inspec
|
|||
targets.each { |target| runner.add_target(target, opts) }
|
||||
exit runner.run
|
||||
rescue RuntimeError => e
|
||||
puts e.message
|
||||
$stderr.puts e.message
|
||||
exit 1
|
||||
end
|
||||
|
||||
def diagnose
|
||||
|
|
|
@ -183,4 +183,22 @@ describe 'inspec exec' do
|
|||
File.exist?('/tmp/inspec_test_DONT_CREATE').must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a profile that is supported on this version of inspec' do
|
||||
let(:out) { inspec('exec ' + File.join(profile_path, 'supported_inspec')) }
|
||||
|
||||
it 'exits cleanly' do
|
||||
out.stderr.must_equal ''
|
||||
out.exit_status.must_equal 0
|
||||
end
|
||||
end
|
||||
|
||||
describe 'with a profile that is not supported on this version of inspec' do
|
||||
let(:out) { inspec('exec ' + File.join(profile_path, 'unsupported_inspec')) }
|
||||
|
||||
it 'does not support this profile' do
|
||||
out.exit_status.must_equal 1
|
||||
out.stderr.must_equal "This profile requires InSpec version >= 99.0.0. You are running InSpec v#{Inspec::VERSION}.\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
2
test/unit/mock/profiles/supported_inspec/inspec.yml
Normal file
2
test/unit/mock/profiles/supported_inspec/inspec.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
supports:
|
||||
- inspec: 0.18
|
2
test/unit/mock/profiles/unsupported_inspec/inspec.yml
Normal file
2
test/unit/mock/profiles/unsupported_inspec/inspec.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
supports:
|
||||
- inspec: '>= 99.0.0'
|
Loading…
Reference in a new issue