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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/kitchen/verifier/inspec.rb', line 76 def call(state) logger.debug("Initialize InSpec") # gather connection options opts = (instance.transport, state, instance.platform.name, instance.suite.name) logger.debug "Options #{opts.inspect}" # add inputs setup_inputs(opts, config) # setup Inspec ::Inspec::Log.init(STDERR) ::Inspec::Log.level = Kitchen::Util.from_logger_level(logger.level) inspec_config = ::Inspec::Config.new(opts) # handle plugins load_plugins setup_plugin_config(inspec_config) # initialize runner runner = ::Inspec::Runner.new(inspec_config) # add each profile to runner tests = collect_tests profile_ctx = nil tests.each do |target| profile_ctx = runner.add_target(target) end profile_ctx ||= [] profile_ctx.each do |profile| logger.info("Loaded #{profile.name} ") end exit_code = runner.run # 101 is a success as well (exit with no fails but has skipped controls) return if exit_code == 0 || exit_code == 101 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/kitchen/verifier/inspec.rb', line 59 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 |