Class: Kitchen::Verifier::Inspec
- Inherits:
-
Base
- Object
- Base
- Kitchen::Verifier::Inspec
- Defined in:
- lib/kitchen/verifier/inspec.rb
Overview
InSpec verifier for Kitchen.
Instance Method Summary collapse
- #call(state) ⇒ Object
-
#finalize_config!(instance) ⇒ self
A lifecycle method that should be invoked when the object is about ready to be used.
Instance Method Details
#call(state) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kitchen/verifier/inspec.rb', line 65 def call(state) logger.debug("Initialize InSpec") # gather connection options opts = (instance.transport, state, instance.platform.name, instance.suite.name) # add attributes 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| 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 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.
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 |