Class: CemAcpt::TestData::Fetcher

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/cem_acpt/test_data.rb

Overview

Fetcher provides the methods for extracting and formatting test data.

Constant Summary

Constants included from Logging

Logging::LEVEL_MAP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

current_log_config, #current_log_config, current_log_format, #current_log_format, #current_log_level, current_log_level, included, #logger, logger, new_log_config, #new_log_config, new_log_formatter, #new_log_formatter, #new_log_level, new_log_level, #new_logger, new_logger, verbose?, #verbose?

Constructor Details

#initialize(config) ⇒ Fetcher

Initializes a new Fetcher object.

Parameters:



27
28
29
30
31
# File 'lib/cem_acpt/test_data.rb', line 27

def initialize(config)
  @config = config
  @acpt_test_dir = Pathname(File.join(@config.get('module_dir'), 'spec', 'acceptance'))
  find_acceptance_tests!
end

Instance Attribute Details

#acceptance_testsObject (readonly)

Returns the value of attribute acceptance_tests.



23
24
25
# File 'lib/cem_acpt/test_data.rb', line 23

def acceptance_tests
  @acceptance_tests
end

#acpt_test_dirObject (readonly)

Returns the value of attribute acpt_test_dir.



23
24
25
# File 'lib/cem_acpt/test_data.rb', line 23

def acpt_test_dir
  @acpt_test_dir
end

Instance Method Details

#acceptance_test_dataArray<Hash>

Extracts, formats, and returns a test data hash.

Returns:

  • (Array<Hash>)

    an array of test data hashes



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cem_acpt/test_data.rb', line 35

def acceptance_test_data
  logger.info('CemAcpt::TestData') { 'Gathering acceptance test data...' }
  raise "No 'tests' entry found in config" unless @config.has?('tests')

  @config.get('tests').each_with_object([]) do |test_name, a|
    test_dir = acceptance_tests.find { |f| File.basename(f) == test_name }
    raise "Test directory not found for test #{test_name}" unless test_dir

    goss_file = File.expand_path(File.join(test_dir, 'goss.yaml'))
    puppet_manifest = File.expand_path(File.join(test_dir, 'manifest.pp'))
    raise "Goss file not found for test #{test_name}" unless File.exist?(goss_file)
    raise "Puppet manifest not found for test #{test_name}" unless File.exist?(puppet_manifest)

    bolt_test = File.expand_path(File.join(test_dir, 'bolt.yaml'))
    logger.debug('CemAcpt::TestData') { "Complete test directory found for test #{test_name}: #{test_dir}" }
    test_data = {
      test_name: test_name,
      test_dir: File.expand_path(test_dir),
      goss_file: goss_file,
      puppet_manifest: puppet_manifest,
    }
    test_data[:bolt_test] = bolt_test if File.exist?(bolt_test)

    process_for_each(test_data).each do |test_data_i|
      process_static_vars(test_data_i)
      process_name_pattern_vars(test_name, test_data_i)
      vars_post_processing!(test_data_i)
      test_data_i.format!
      a << test_data_i
    end
  end
end