Skip to content

Commit

Permalink
activate logger, use info from inspec
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hartmann <[email protected]>
  • Loading branch information
chris-rock committed Dec 8, 2016
1 parent 26e01ec commit d60073c
Showing 1 changed file with 11 additions and 29 deletions.
40 changes: 11 additions & 29 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,23 @@ def call(state)
opts[:attrs] = config[:attrs]
opts[:attributes] = Hashie.stringify_keys config[:attributes] unless config[:attributes].nil?

# setup logger
::Inspec::Log.init(STDERR)
::Inspec::Log.level = Kitchen::Util.from_logger_level(logger.level)

# initialize runner
runner = ::Inspec::Runner.new(opts)

# add each profile to runner
tests = collect_tests
profile_ctx = nil
tests.each do |target|
logger.info("Loading Inspect Profile from #{test_location(target)}")
runner.add_target(target, opts)
profile_ctx = runner.add_target(target, opts)
end

profile_ctx ||= []
profile_ctx.each do |profile|
logger.info("Loaded #{profile.name} ")
end

exit_code = runner.run
Expand All @@ -89,33 +98,6 @@ def call(state)

private

# Print out where we are loading the tests from for clarity
#
# @param target [String, Hash] One of the values from the inspec_tests setting
# @return [String] Description of from where the tests are being loaded
# @api private
def test_location(target)
case target
when String
target
when Hash
if target[:name]
keys = target.keys.dup
keys.delete(:name)
type, location = if keys.empty?
["supermarket", target[:name]]
else
[keys[0], target[keys[0]]]
end

"#{target[:name]} (#{type}: #{location})"
else
src = target.keys[0]
"#{src}: #{target[src]}"
end
end
end

# (see Base#load_needed_dependencies!)
def load_needed_dependencies!
require "inspec"
Expand Down

0 comments on commit d60073c

Please sign in to comment.