Merge pull request #5266 from inspec/ns/cust_issue

This commit is contained in:
Clinton Wolfe 2021-03-16 16:11:35 -04:00 committed by GitHub
commit 640ce91d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 1 deletions

View file

@ -395,6 +395,20 @@ class Inspec::InspecCLI < Inspec::BaseCLI
end
map %w{-v --version} => :version
desc "clear_cache", "clears the InSpec cache. Useful for debugging."
option :vendor_cache, type: :string,
desc: "Use the given path for caching dependencies. (default: ~/.inspec/cache)"
def clear_cache
o = config
configure_logger(o)
cache_path = o[:vendor_cache] || "~/.inspec/cache"
FileUtils.rm_r Dir.glob(File.expand_path(cache_path))
o[:logger] = Logger.new($stdout)
o[:logger].level = get_log_level(o[:log_level])
o[:logger].info "== InSpec cache cleared successfully =="
end
private
def run_command(opts)

View file

@ -5,7 +5,7 @@ require "matchers/matchers"
require "inspec/rspec_extensions"
# There be dragons!! Or borgs, or something...
# This file and all its contents cannot be unit-tested. both test-suits
# This file and all its contents cannot be unit-tested. both test-suites
# collide and disable all unit tests that have been added.
module Inspec

View file

@ -0,0 +1,27 @@
require "functional/helper"
require "securerandom"
describe "inspec check" do
include FunctionalHelper
parallelize_me!
describe "inspec clear_cache" do
it "clears any existing cache" do
dirname = File.expand_path("~/.inspec/#{SecureRandom.hex(10)}/alt-cache")
unless File.directory?(dirname)
FileUtils.mkdir_p(dirname)
end
newfile = "#{dirname}/#{SecureRandom.hex(10)}.txt"
File.write(newfile, SecureRandom.hex(100))
assert !Dir.glob(newfile).empty?
out = inspec("clear_cache --vendor-cache=#{dirname}")
assert_empty Dir.glob(newfile)
assert_exit_code 0, out
_(out.stdout).must_include "== InSpec cache cleared successfully ==\n"
end
end
end