Class: Kitchen::Verifier::Inspec

Inherits:
Base
  • Object
show all
Defined in:
lib/kitchen/verifier/inspec.rb

Overview

InSpec verifier for Kitchen.

Instance Method Summary collapse

Instance Method Details

#call(state) ⇒ Object

Raises:

  • (ActionFailed)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kitchen/verifier/inspec.rb', line 65

def call(state)
  logger.debug("Initialize InSpec")

  # gather connection options
  opts = runner_options(instance.transport, state)

  # add attributes
  opts[:attrs] = config[:attrs]
  opts[:attributes] = Hashie.stringify_keys config[:attributes] unless config[:attributes].nil?

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

  # add each profile to runner
  tests = collect_tests
  tests.each { |target| runner.add_target(target, opts) }

  logger.debug("Running tests from: #{tests.inspect}")
  exit_code = runner.run
  return if exit_code == 0
  raise ActionFailed, "Inspec Runner returns #{exit_code}"
end

#finalize_config!(instance) ⇒ self

A lifecycle method that should be invoked when the object is about ready to be used. A reference to an Instance is required as configuration dependant data may be access through an Instance. This also acts as a hook point where the object may wish to perform other last minute checks, validations, or configuration expansions.

Parameters:

  • instance (Instance)

    an associated instance

Returns:

  • (self)

    itself, for use in chaining

Raises:

  • (ClientError)

    if instance parameter is nil



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/kitchen/verifier/inspec.rb', line 48

def finalize_config!(instance)
  super

  # We want to switch kitchen-inspec to look for its tests in
  # `cookbook_dir/test/recipes` instead of `cookbook_dir/test/integration`
  # Unfortunately there is no way to read `test_base_path` from the
  # .kitchen.yml, it can only be provided on the CLI.
  # See https://github.com/test-kitchen/test-kitchen/issues/1077
  inspec_test_dir = File.join(config[:kitchen_root], "test", "recipes")
  if File.directory?(inspec_test_dir)
    config[:test_base_path] = inspec_test_dir
  end

  self
end