From 09d3f4bb51bbbc91e47b4a70b887041eaf95c4b2 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Thu, 8 Dec 2016 11:28:54 +0000 Subject: [PATCH] activate logger, use info from inspec --- lib/kitchen/verifier/inspec.rb | 39 +++++++++------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 0d36c10..fdd204a 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -72,16 +72,24 @@ 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 = [] 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.each { |profile| + logger.info("Loaded #{profile.name} ") + } + exit_code = runner.run return if exit_code == 0 raise ActionFailed, "Inspec Runner returns #{exit_code}" @@ -89,33 +97,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"