Functional test and fixtures for git fetcher fallback

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-12-11 14:40:54 -05:00
parent f9d419f219
commit 928cf6f05e
12 changed files with 72 additions and 2 deletions

View file

@ -0,0 +1,5 @@
control "dep-on-missing-01" do
describe "a string" do
it { should cmp "a string" }
end
end

View file

@ -0,0 +1 @@
include_controls('inspec-test-profile-missing')

View file

@ -0,0 +1,10 @@
name: git-deps-on-missing
license: Apache-2.0
summary: An inspec profile that has a git dependency on a profile that was deleted
version: 0.1.0
supports:
platform: os
depends:
- name: inspec-test-profile-missing
# git requires a leading slash, so rely on ERB to interpolate in the PWD...
git: /<%= Dir.pwd %>/inspec-test-profile-missing

View file

@ -0,0 +1,5 @@
# inspec-test-profile-missing
This is a Chef InSpec profile. It is used in the testing of InSpec itself. This profile was inserted into archives, then the name of the repo was changed, so that it would become unfetchable. This allows us to test the fetchers when they cannot resolve a profile.
This repo is part of the testing material of InSpec itself, and is not intended for public use. No support is provided.

View file

@ -0,0 +1 @@
include_controls('inspec-test-profile-basic')

View file

@ -0,0 +1,5 @@
control "missing-01" do
describe "a string" do
it { should cmp "a string" }
end
end

View file

@ -0,0 +1,9 @@
name: inspec-test-profile-missing
title: InSpec Profile
summary: An InSpec Compliance Profile that will end up unresolvable but archived
version: 0.1.0
supports:
platform: os
depends:
- name: inspec-test-profile-basic
git: https://github.com/inspec/inspec-test-profile-basic.git

View file

@ -0,0 +1 @@
include_controls('git-deps-on-missing')

View file

@ -0,0 +1,5 @@
control "local-dep-01" do
describe "a string" do
it { should cmp "a string" }
end
end

View file

@ -0,0 +1,9 @@
name: local-dep-on-bad-git-archive
license: Apache-2.0
summary: A profile that relies on an archive that has an unresolvable git dependency
version: 0.1.0
supports:
platform: os
depends:
- name: git-deps-on-missing
path: ../git-deps-on-missing-0.1.0.tar.gz

View file

@ -1,16 +1,16 @@
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) }
let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" }
# Refs #4726
describe "when fetchers fetch a bad dependency" do
let(:fetcher_profiles) { "#{profile_path}/fetcher-failures" }
parallelize_me!
def assert_fetcher_failed_cleanly(run_result, error_regex, profile_location)
_(run_result.stdout).must_be_empty
@ -54,4 +54,23 @@ describe "the fetchers" do
end
end
# Refs #4727
describe "when a archive is available of an unfetchable profile with --airgap" do
let(:invocation) { "archive #{path} --airgap" }
let(:path) { "#{fetcher_profiles}/local-dep-on-bad-git-archive" }
def teardown
FileUtils.rm_rf "#{path}/vendor"
FileUtils.rm_rf "#{fetcher_profiles}/local-dep-on-bad-git-archive-0.1.0.tar.gz"
end
it "should be able to create a new archive wrapping the profile" do
# Cannot be parallelized - must purge cache to test properly
_(run_result.stderr).must_be_empty
_(run_result.stdout).must_include "Finished archive generation"
assert_exit_code(0, run_result)
end
end
end