Refactor functional test to DRY up

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-11-20 13:02:37 -05:00
parent 8679443698
commit 6b0877591f

View file

@ -12,36 +12,44 @@ describe "the fetchers" do
describe "when fetchers fetch a bad dependency" do
let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" }
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
describe "when using the local fetcher on a bad dep" do
let(:path) { "#{fetcher_profiles}/local-bad" }
it "should throw an exception not a stacktrace" do
_(run_result.stdout).must_be_empty
_(run_result.stderr).wont_match looks_like_a_stacktrace
_(run_result.stderr).must_match(/Profile dependency local path .+ does not exist/)
_(run_result.stderr).must_include "fetcher-failures/nonesuch" # path of the missing profile in message
assert_exit_code(1, run_result)
assert_fetcher_failed_cleanly(
run_result,
/Profile dependency local path .+ does not exist/,
"fetcher-failures/nonesuch"
)
end
end
describe "when using the url fetcher on a bad dep" do
let(:path) { "#{fetcher_profiles}/url-bad" }
it "should throw an exception not a stacktrace" do
_(run_result.stdout).must_be_empty
_(run_result.stderr).wont_match looks_like_a_stacktrace
_(run_result.stderr).must_match(/Profile URL dependency .+ could not be fetched:/)
_(run_result.stderr).must_include "https://localhost/inspec/inspec-nonesuch/path/to/profile.tgz" # URL of the missing profile in message
assert_exit_code(1, run_result)
assert_fetcher_failed_cleanly(
run_result,
/Profile URL dependency .+ could not be fetched:/,
"https://localhost/inspec/inspec-nonesuch/path/to/profile.tgz"
)
end
end
describe "when using the url fetcher on a bad dep" do
let(:path) { "#{fetcher_profiles}/git-bad" }
it "should throw an exception not a stacktrace" do
_(run_result.stdout).must_be_empty
_(run_result.stderr).wont_match looks_like_a_stacktrace
_(run_result.stderr).must_match(/Profile git dependency failed for .+ Connection refused/)
_(run_result.stderr).must_include "http://localhost/no/such" # URL of the missing profile in message
assert_exit_code(1, run_result)
assert_fetcher_failed_cleanly(
run_result,
/Profile git dependency failed for .+ Connection refused/,
"http://localhost/no/such"
)
end
end