Skip to content

Commit

Permalink
Tweak logging for clarity
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tduffield committed Dec 7, 2016
1 parent c1f4302 commit 26e01ec
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,45 @@ 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}"
end

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 Expand Up @@ -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 }] : []
Expand Down

0 comments on commit 26e01ec

Please sign in to comment.