From 26e01ece9a5be4409a02f6baa3806cecc5ce361e Mon Sep 17 00:00:00 2001 From: Tom Duffield Date: Tue, 6 Dec 2016 15:50:54 -0600 Subject: [PATCH] Tweak logging for clarity Do not print an info message saying that we are loading tests from the test_base_dir unless we actually are. This can be confusing for first-time users who may not even have that directory (if they used ChefDK to generate the .kitchen.yml). Rather, iterate through the targets that we _are_ testing and log those. Signed-off-by: Tom Duffield --- lib/kitchen/verifier/inspec.rb | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 363dd8e..0d36c10 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -77,9 +77,11 @@ def call(state) # add each profile to runner tests = collect_tests - tests.each { |target| runner.add_target(target, opts) } + tests.each do |target| + logger.info("Loading Inspect Profile from #{test_location(target)}") + runner.add_target(target, opts) + end - logger.debug("Running tests from: #{tests.inspect}") exit_code = runner.run return if exit_code == 0 raise ActionFailed, "Inspec Runner returns #{exit_code}" @@ -87,6 +89,33 @@ 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" @@ -127,7 +156,6 @@ def local_suite_files end base = File.join(base, "inspec") if legacy_mode - logger.info("Using `#{base}` for testing") # only return the directory if it exists Pathname.new(base).exist? ? [{ :path => base }] : []