Fix bundle exec calls (#2670)

* Fix bundle exec calls and add test.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add exit check for supermarket exec.

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-02-17 10:49:52 -05:00 committed by Christoph Hartmann
parent 4641978716
commit 457a33a2b3
3 changed files with 51 additions and 6 deletions

View file

@ -78,11 +78,20 @@ module Compliance
def exec(*tests) def exec(*tests)
config = Compliance::Configuration.new config = Compliance::Configuration.new
return if !loggedin(config) return if !loggedin(config)
o = opts(:exec).dup
diagnose(o)
configure_logger(o)
# iterate over tests and add compliance scheme # iterate over tests and add compliance scheme
tests = tests.map { |t| 'compliance://' + Compliance::API.sanitize_profile_name(t) } tests = tests.map { |t| 'compliance://' + Compliance::API.sanitize_profile_name(t) }
# execute profile from inspec exec implementation
diagnose runner = Inspec::Runner.new(o)
run_tests(tests, opts) tests.each { |target| runner.add_target(target) }
exit runner.run
rescue ArgumentError, RuntimeError, Train::UserError => e
$stderr.puts e.message
exit 1
end end
desc 'download PROFILE', 'downloads a profile from Chef Compliance' desc 'download PROFILE', 'downloads a profile from Chef Compliance'

View file

@ -29,12 +29,20 @@ module Supermarket
desc 'exec PROFILE', 'execute a Supermarket profile' desc 'exec PROFILE', 'execute a Supermarket profile'
exec_options exec_options
def exec(*tests) def exec(*tests)
o = opts(:exec).dup
diagnose(o)
configure_logger(o)
# iterate over tests and add compliance scheme # iterate over tests and add compliance scheme
tests = tests.map { |t| 'supermarket://' + t } tests = tests.map { |t| 'supermarket://' + t }
# execute profile from inspec exec implementation runner = Inspec::Runner.new(o)
diagnose tests.each { |target| runner.add_target(target) }
run_tests(tests, opts)
exit runner.run
rescue ArgumentError, RuntimeError, Train::UserError => e
$stderr.puts e.message
exit 1
end end
desc 'info PROFILE', 'display Supermarket profile details' desc 'info PROFILE', 'display Supermarket profile details'

View file

@ -0,0 +1,28 @@
# encoding: utf-8
require 'functional/helper'
describe 'inspec supermakert' do
include FunctionalHelper
it 'help' do
out = inspec('supermarket help')
out.exit_status.must_equal 0
out.stdout.must_include 'inspec supermarket exec PROFILE'
end
it 'info' do
out = inspec('supermarket info dev-sec/ssh-baseline')
out.exit_status.must_equal 0
out.stderr.must_equal ''
out.stdout.must_include "name: \e[0m ssh-baseline"
end
it 'supermarket exec' do
out = inspec('supermarket exec dev-sec/ssh-baseline')
out.exit_status.wont_equal 1
out.stderr.must_equal ''
out.stdout.must_include 'Profile Summary'
out.stdout.must_include 'Test Summary'
end
end