Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix duplicate testing when unique suite name #114

Merged
merged 3 commits into from
Nov 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,29 @@ 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
# @return [Array<String>] array of suite directories or remote urls
# @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`.
Expand Down
16 changes: 8 additions & 8 deletions spec/kitchen/verifier/inspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,23 +206,23 @@
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

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
Expand Down Expand Up @@ -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"),
}
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/integration/duplicates/dup.rb
Original file line number Diff line number Diff line change
@@ -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