diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 9dabee7..6ec787f 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -122,7 +122,18 @@ def local_suite_files logger.info("Using `#{base}` for testing") # only return the directory if it exists - Pathname.new(base).exist? ? [base] : [] + Pathname.new(base).exist? ? [{ :path => base }] : [] + end + + # Takes config[:inspec_tests] and modifies any value with a key of :path by adding the full path + # @return [Array] array of modified hashes + # @api private + def resolve_config_inspec_tests + config[:inspec_tests].map do |test_hash| + raise Kitchen::UserError, "Please specify your inspec tests using the format `path: path/to/file` or `url: url_address`. See README for more information." unless test_hash.is_a? Hash + test_hash = { :path => config[:kitchen_root] + "/" + test_hash[:path] } if test_hash.has_key?(:path) + test_hash + end end # Returns an array of test profiles @@ -130,7 +141,7 @@ def local_suite_files # @api private def collect_tests # get local tests and get run list of profiles - (local_suite_files + config[:inspec_tests]).compact + (local_suite_files + resolve_config_inspec_tests).compact.uniq end # Returns a configuration Hash that can be passed to a `Inspec::Runner`. diff --git a/spec/kitchen/verifier/inspec_spec.rb b/spec/kitchen/verifier/inspec_spec.rb index 2d9af8b..763229c 100644 --- a/spec/kitchen/verifier/inspec_spec.rb +++ b/spec/kitchen/verifier/inspec_spec.rb @@ -206,11 +206,11 @@ it "find test directory for runner" do ensure_suite_directory("germany") allow(Inspec::Runner).to receive(:new).and_return(runner) - expect(runner).to receive(:add_target).with( + expect(runner).to receive(:add_target).with({ :path => File.join( config[:test_base_path], "germany" - ), anything) + ) }, anything) verifier.call({}) end @@ -218,11 +218,11 @@ it "find test directory for runner if legacy" do create_legacy_test_directories allow(Inspec::Runner).to receive(:new).and_return(runner) - expect(runner).to receive(:add_target).with( + expect(runner).to receive(:add_target).with({ :path => File.join( config[:test_base_path], "germany", "inspec" - ), anything) + ) }, anything) verifier.call({}) end @@ -274,7 +274,7 @@ let(:config) do { - inspec_tests: ["https://github.com/nathenharvey/tmp_compliance_profile"], + inspec_tests: [{ :url => "https://github.com/nathenharvey/tmp_compliance_profile" }], kitchen_root: kitchen_root, test_base_path: File.join(kitchen_root, "test", "integration"), } @@ -288,10 +288,10 @@ it "find test directory and remote profile" do ensure_suite_directory("local") allow(Inspec::Runner).to receive(:new).and_return(runner) + expect(runner).to receive(:add_target).with({ :path => + File.join(config[:test_base_path], "local") }, anything) expect(runner).to receive(:add_target).with( - File.join(config[:test_base_path], "local"), anything) - expect(runner).to receive(:add_target).with( - "https://github.com/nathenharvey/tmp_compliance_profile", anything) + { :url => "https://github.com/nathenharvey/tmp_compliance_profile" }, anything) verifier.call({}) end end