Code climate updates

Signed-off-by: Clinton Wolfe <clintoncwolfe@gmail.com>
This commit is contained in:
Clinton Wolfe 2019-06-20 14:56:57 -04:00
parent abc5e84b87
commit c03862fe7b
3 changed files with 21 additions and 17 deletions

View file

@ -5,6 +5,9 @@ checks:
identical-code:
config:
threshold: 40 # Unfortunately, we have a lot of duplicate code in places like lib/inspec/control_eval_context.rb
method-complexity: # 'Cognitive Complexity' in the UI
config:
threshold: 10 # 5 Default 5 is really tight
plugins:
fixme:
enabled: true

View file

@ -68,19 +68,7 @@ module Fetchers
Dir.mktmpdir do |working_dir|
checkout(working_dir)
if @relative_path
Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
"Moving #{@relative_path} to #{destination_path}")
unless File.exist?("#{working_dir}/#{@relative_path}")
# Cleanup the destination path - otherwise we'll have an empty dir
# in the cache, which is enough to confuse the cache reader
# This is acourtesy, assuming we're writing to the cache; if we're
# vendoring to somthing more complex, don't bother.
FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)
raise ArgumentError.new("Cannot find relative path '#{@relative_path}' " \
"within profile in git repo specified by '#{@remote_url}'")
end
FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
perform_relative_path_fetch(destination_path, working_dir)
else
Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
"Moving checkout to #{destination_path}")
@ -91,6 +79,22 @@ module Fetchers
@repo_directory
end
def perform_relative_path_fetch(destination_path, working_dir)
Inspec::Log.debug("Checkout of #{resolved_ref} successful. " \
"Moving #{@relative_path} to #{destination_path}")
unless File.exist?("#{working_dir}/#{@relative_path}")
# Cleanup the destination path - otherwise we'll have an empty dir
# in the cache, which is enough to confuse the cache reader
# This is acourtesy, assuming we're writing to the cache; if we're
# vendoring to somthing more complex, don't bother.
FileUtils.rmdir(destination_path) if Dir.empty?(destination_path)
raise ArgumentError.new("Cannot find relative path '#{@relative_path}' " \
"within profile in git repo specified by '#{@remote_url}'")
end
FileUtils.cp_r("#{working_dir}/#{@relative_path}", destination_path)
end
def cache_key
return resolved_ref unless @relative_path
OpenSSL::Digest::SHA256.hexdigest(resolved_ref + @relative_path)

View file

@ -68,7 +68,7 @@ describe "running profiles with git-based dependencies" do
#======================================================================#
# Revision Selection
#======================================================================#
# TODO: test branch, rev, and tag capabilities
# NOTE: test branch, rev, and tag capabilities are tested in unit tests
#======================================================================#
# Relative Path Support
@ -99,9 +99,6 @@ describe "running profiles with git-based dependencies" do
#------------ Edge Cases for Relative Path Support -------------------#
# TODO: These next two tests trigger a bug, in which the profile appears
# to have a key collision in the cache.
describe "running a profile with an '' relative path dependency" do
it "should find the top-level profile in the git-referenced child profile and execute that" do
assert_relative_fetch_works("relative-empty", ["relative-empty", "basic-local"], ["relative-empty-01", "basic-local-01"])