Class: CemWinSpec::FixtureCache
- Inherits:
-
Object
- Object
- CemWinSpec::FixtureCache
- Defined in:
- lib/cem_win_spec/fixture_cache.rb
Overview
Class for managing cached fixtures Fixture caching is used to speed up test runs by reusing the same Puppet modules between test runs instead of downloading them each time. The cache works by creating a YAML file that maps module names and
Constant Summary collapse
- CACHE_DIR =
'C:/cem_win_spec'
- CACHE_MANIFEST =
'cache_manifest.yaml'
Instance Attribute Summary collapse
-
#cache_dir ⇒ Object
readonly
Returns the value of attribute cache_dir.
-
#cache_entries ⇒ Object
readonly
Returns the value of attribute cache_entries.
Class Method Summary collapse
Instance Method Summary collapse
- #copy_fixtures_to(fixtures_dir, make_fixtures_dir: true) ⇒ Object
-
#initialize ⇒ FixtureCache
constructor
A new instance of FixtureCache.
- #setup! ⇒ Object
Constructor Details
#initialize ⇒ FixtureCache
Returns a new instance of FixtureCache.
28 29 30 31 32 33 34 35 |
# File 'lib/cem_win_spec/fixture_cache.rb', line 28 def initialize validate_platform! @cache_dir = CACHE_DIR @cache_entries = setup_and_load_cache @entries_digest = hexdigest(@cache_entries.to_s) @dependencies = setup! end |
Instance Attribute Details
#cache_dir ⇒ Object (readonly)
Returns the value of attribute cache_dir.
26 27 28 |
# File 'lib/cem_win_spec/fixture_cache.rb', line 26 def cache_dir @cache_dir end |
#cache_entries ⇒ Object (readonly)
Returns the value of attribute cache_entries.
26 27 28 |
# File 'lib/cem_win_spec/fixture_cache.rb', line 26 def cache_entries @cache_entries end |
Class Method Details
Instance Method Details
#copy_fixtures_to(fixtures_dir, make_fixtures_dir: true) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cem_win_spec/fixture_cache.rb', line 53 def copy_fixtures_to(fixtures_dir, make_fixtures_dir: true) ::FileUtils.mkdir_p(fixtures_dir) if make_fixtures_dir raise "Directory #{fixtures_dir} does not exist" unless File.directory?(fixtures_dir) @cache_entries.each do |_, path| final_mod_path = File.join(fixtures_dir, File.basename(path).split('-').last) ::FileUtils.remove_entry_secure(final_mod_path) if File.exist?(final_mod_path) ::FileUtils.cp_r(path, final_mod_path) puts "Copied #{path} to #{final_mod_path}" end rescue StandardError => e handle_error(e, "Failed to copy fixtures to #{fixtures_dir}") end |
#setup! ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cem_win_spec/fixture_cache.rb', line 37 def setup! @dependencies.each do |name, data| if cached?(data[:checksum]) puts "Using cached #{name} #{data[:version]}" next end puts "Downloading #{name} #{data[:version]}..." download_and_cache(name, data[:release_slug], data[:checksum]) end rescue StandardError => e handle_error(e, 'Failed to setup fixture cache') ensure save_cache_entries end |