skip profiles if the platform isnt supported

This commit is contained in:
Dominik Richter 2016-04-16 15:34:23 -04:00
parent a1188b26ce
commit 14995534cd
5 changed files with 31 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
supports:
- inspec: 0.18

View file

@ -0,0 +1,2 @@
supports:
- inspec: '>= 99.0.0'