diff --git a/.kitchen.yml b/.kitchen.yml index 867d119..9586f4d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -44,6 +44,13 @@ suites: verifier: inspec_tests: - https://github.com/nathenharvey/tmp_compliance_profile.git + - name: duplicates + run_list: + - recipe[os_prepare] + verifier: + inspec_tests: + - path: ./test/integration/duplicates + - path: ./test/integration/duplicates # before you are able to use the compliance plugin, you need to run # insecure is only required if you use self-signed certificates # $ inspec compliance login https://compliance.test --user admin --insecure --token '' diff --git a/.travis.yml b/.travis.yml index cec6464..10ad39a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,6 +23,10 @@ matrix: bundler_args: "--without guard tools" script: bundle exec rake $SUITE env: SUITE="test:integration" OS='backwards' + - rvm: 2.3.1 + bundler_args: "--without guard tools" + script: bundle exec rake $SUITE + env: SUITE="test:integration" OS='duplicates' - rvm: 2.3.1 bundler_args: "--without guard tools" script: bundle exec rake $SUITE diff --git a/lib/kitchen/verifier/inspec.rb b/lib/kitchen/verifier/inspec.rb index 9dabee7..e2af42e 100644 --- a/lib/kitchen/verifier/inspec.rb +++ b/lib/kitchen/verifier/inspec.rb @@ -122,7 +122,21 @@ 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| + if test_hash.is_a? Hash + test_hash = { :path => config[:kitchen_root] + "/" + test_hash[:path] } if test_hash.has_key?(:path) + test_hash + else + test_hash # if it's not a hash, just return it as is + end + end end # Returns an array of test profiles @@ -130,7 +144,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 diff --git a/test/integration/duplicates/dup.rb b/test/integration/duplicates/dup.rb new file mode 100644 index 0000000..6dc5970 --- /dev/null +++ b/test/integration/duplicates/dup.rb @@ -0,0 +1,13 @@ +# encoding: utf-8 + +# This is an InSpec test, that will be successful the first run. If it is +# executed the second time, the test will fail +path = "/tmp/file" +describe file(path) do + it { should_not exist } +end + +# HACK: create a second file to fail tests if they run twice +describe command("mkdir -p #{path}") do + its("exit_status") { should eq 0 } +end