# This test is intended to verify that the `--no-cache` command line flag will # cause facter to not refresh a cached fact that is expired test_name "C100124: --no-cache does not refresh expired cached facts" do tag 'risk:high' require 'facter/acceptance/user_fact_utils' extend Facter::Acceptance::UserFactUtils # the uptime fact should be resolvable on ALL systems # Note: do NOT use the kernel fact, as it is used to configure the tests cached_fact_name = "uptime" bad_cached_fact_value = "CACHED_FACT_VALUE" bad_cached_content = < [0, 1]) on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) end step "Agent #{agent}: create config file in default location" do on(agent, "mkdir -p '#{config_dir}'") create_remote_file(agent, config_file, config) end step "facter should not refresh an expired cache when --no-cache is specified" do # clear the fact cache on(agent, "rm -rf '#{cached_facts_dir}'", :acceptable_exit_codes => [0, 1]) # run once to cache the uptime fact on(agent, facter("")) # override cached content create_remote_file(agent, cached_fact_file, bad_cached_content) # update the modify time on the new cached fact to prompt a refresh on(agent, "touch -mt 0301010000 '#{cached_fact_file}'") on(agent, facter("--no-cache")) do |facter_output| assert_no_match(/caching/, facter_output.stderr, "facter should not have tried to refresh the cache") end on(agent, "cat '#{cached_fact_file}'", :acceptable_exit_codes => [0]) do |cat_output| assert_match(/#{bad_cached_content}/, cat_output.stdout, "facter should not have updated the cached value") end end end end