mirror of
https://github.com/inspec/inspec
synced 2024-11-23 21:23:29 +00:00
fixture and implementation for git fetcher failure handling
Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
parent
c1d1e6d12f
commit
4bda0ddeeb
2 changed files with 14 additions and 5 deletions
|
@ -90,8 +90,8 @@ module Inspec::Fetcher
|
||||||
# vendoring to something more complex, don't bother.
|
# vendoring to something more complex, don't bother.
|
||||||
FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)
|
FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)
|
||||||
|
|
||||||
raise ArgumentError, "Cannot find relative path '#{@relative_path}' " \
|
raise Inspec::FetcherFailure.new("Cannot find relative path '#{@relative_path}' " \
|
||||||
"within profile in git repo specified by '#{@remote_url}'"
|
"within profile in git repo specified by '#{@remote_url}'")
|
||||||
end
|
end
|
||||||
FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
|
FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
|
||||||
end
|
end
|
||||||
|
@ -129,11 +129,11 @@ module Inspec::Fetcher
|
||||||
def resolve_ref(ref_name)
|
def resolve_ref(ref_name)
|
||||||
command_string = "git ls-remote \"#{@remote_url}\" \"#{ref_name}*\""
|
command_string = "git ls-remote \"#{@remote_url}\" \"#{ref_name}*\""
|
||||||
cmd = shellout(command_string)
|
cmd = shellout(command_string)
|
||||||
raise "Error running '#{command_string}': #{cmd.stderr}" unless cmd.exitstatus == 0
|
raise Inspec::FetcherFailure.new("Profile git dependency failed for #{@remote_url} - error running '#{command_string}': #{cmd.stderr}") unless cmd.exitstatus == 0
|
||||||
|
|
||||||
ref = parse_ls_remote(cmd.stdout, ref_name)
|
ref = parse_ls_remote(cmd.stdout, ref_name)
|
||||||
unless ref
|
unless ref
|
||||||
raise "Unable to resolve #{ref_name} to a specific git commit for #{@remote_url}"
|
raise Inspec::FetcherFailure.new("Profile git dependency failed - unable to resolve #{ref_name} to a specific git commit for #{@remote_url}")
|
||||||
end
|
end
|
||||||
|
|
||||||
ref
|
ref
|
||||||
|
@ -191,7 +191,7 @@ module Inspec::Fetcher
|
||||||
cmd.error!
|
cmd.error!
|
||||||
cmd.status
|
cmd.status
|
||||||
rescue Errno::ENOENT
|
rescue Errno::ENOENT
|
||||||
raise "To use git sources, you must have git installed."
|
raise Inspec::FetcherFailure.new("Profile git dependency failed for #{@remote_url} - to use git sources, you must have git installed.")
|
||||||
end
|
end
|
||||||
|
|
||||||
def shellout(cmd, opts = {})
|
def shellout(cmd, opts = {})
|
||||||
|
|
9
test/fixtures/profiles/fetcher-failures/git-bad/inspec.yml
vendored
Normal file
9
test/fixtures/profiles/fetcher-failures/git-bad/inspec.yml
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
name: git-bad
|
||||||
|
license: Apache-2.0
|
||||||
|
summary: A profile with a bad git dependency
|
||||||
|
version: 0.1.0
|
||||||
|
supports:
|
||||||
|
platform: os
|
||||||
|
depends:
|
||||||
|
- name: nonesuch
|
||||||
|
git: http://localhost/no/such
|
Loading…
Reference in a new issue