mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
Merge pull request #5266 from inspec/ns/cust_issue
This commit is contained in:
commit
640ce91d60
3 changed files with 42 additions and 1 deletions
|
@ -395,6 +395,20 @@ class Inspec::InspecCLI < Inspec::BaseCLI
|
||||||
end
|
end
|
||||||
map %w{-v --version} => :version
|
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
|
private
|
||||||
|
|
||||||
def run_command(opts)
|
def run_command(opts)
|
||||||
|
|
|
@ -5,7 +5,7 @@ require "matchers/matchers"
|
||||||
require "inspec/rspec_extensions"
|
require "inspec/rspec_extensions"
|
||||||
|
|
||||||
# There be dragons!! Or borgs, or something...
|
# 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.
|
# collide and disable all unit tests that have been added.
|
||||||
|
|
||||||
module Inspec
|
module Inspec
|
||||||
|
|
27
test/functional/inspec_clear_cache_test.rb
Normal file
27
test/functional/inspec_clear_cache_test.rb
Normal 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
|
Loading…
Reference in a new issue