Skip to content

Commit

Permalink
fix duplicate testing when unique suite name
Browse files Browse the repository at this point in the history
Signed-off-by: Victoria Jeffrey <vjeffrey@chef.io>
  • Loading branch information
Victoria Jeffrey authored and chris-rock committed Nov 4, 2016
1 parent 418a1c6 commit b5a5452
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 13 additions & 2 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,26 @@ 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
# @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

0 comments on commit b5a5452

Please sign in to comment.