2019-11-19 19:45:10 +00:00
|
|
|
require "functional/helper"
|
|
|
|
|
|
|
|
describe "the fetchers" do
|
|
|
|
parallelize_me!
|
|
|
|
include FunctionalHelper
|
|
|
|
|
|
|
|
let(:looks_like_a_stacktrace) { %r{lib/inspec/.+\.rb:\d+:in} }
|
|
|
|
let(:invocation) { "exec #{path} --no-create-lockfile" }
|
|
|
|
let(:run_result) { inspec(invocation) }
|
|
|
|
|
|
|
|
# Refs #4726
|
|
|
|
describe "when fetchers fetch a bad dependency" do
|
|
|
|
let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" }
|
|
|
|
|
2019-11-20 18:02:37 +00:00
|
|
|
def assert_fetcher_failed_cleanly(run_result, error_regex, profile_location)
|
|
|
|
_(run_result.stdout).must_be_empty
|
|
|
|
_(run_result.stderr).wont_match looks_like_a_stacktrace
|
|
|
|
_(run_result.stderr).must_match(error_regex)
|
|
|
|
_(run_result.stderr).must_include profile_location
|
|
|
|
assert_exit_code(1, run_result)
|
|
|
|
end
|
|
|
|
|
2019-11-19 19:45:10 +00:00
|
|
|
describe "when using the local fetcher on a bad dep" do
|
|
|
|
let(:path) { "#{fetcher_profiles}/local-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a local fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
|
|
|
/Profile dependency local path .+ does not exist/,
|
|
|
|
"fetcher-failures/nonesuch"
|
|
|
|
)
|
2019-11-19 19:45:10 +00:00
|
|
|
end
|
|
|
|
end
|
2019-11-19 23:16:34 +00:00
|
|
|
|
|
|
|
describe "when using the url fetcher on a bad dep" do
|
|
|
|
let(:path) { "#{fetcher_profiles}/url-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a url fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
|
|
|
/Profile URL dependency .+ could not be fetched:/,
|
2019-11-25 20:17:33 +00:00
|
|
|
"https://localhost.invalid/inspec/inspec-nonesuch/path/to/profile.tgz"
|
2019-11-20 18:02:37 +00:00
|
|
|
)
|
2019-11-19 23:16:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-25 20:17:33 +00:00
|
|
|
describe "when using the git fetcher on a bad dep" do
|
2019-11-20 17:27:55 +00:00
|
|
|
let(:path) { "#{fetcher_profiles}/git-bad" }
|
2019-11-25 20:17:33 +00:00
|
|
|
it "should throw an exception not a stacktrace with a git fetcher" do
|
2019-11-20 18:02:37 +00:00
|
|
|
assert_fetcher_failed_cleanly(
|
|
|
|
run_result,
|
2019-11-25 20:17:33 +00:00
|
|
|
/Profile git dependency failed for .+ Could not resolve host.+/,
|
|
|
|
"http://localhost.invalid/no/such"
|
2019-11-20 18:02:37 +00:00
|
|
|
)
|
2019-11-20 17:27:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-19 19:45:10 +00:00
|
|
|
end
|
|
|
|
end
|