Method: Onceover::TestConfig#initialize

Defined in:
lib/onceover/testconfig.rb

#initialize(file, opts = {}) ⇒ TestConfig

Returns a new instance of TestConfig.



32
33
34
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/onceover/testconfig.rb', line 32

def initialize(file, opts = {})
  begin
    config = YAML.safe_load(File.read(file), [Symbol])
  rescue Errno::ENOENT
    raise "Could not find #{file}"
  rescue Psych::SyntaxError
    raise "Could not parse #{file}, check that it is valid YAML and that the encoding is correct"
  end

  @classes           = []
  @nodes             = []
  @node_groups       = []
  @class_groups      = []
  @spec_tests        = []
  @acceptance_tests  = []
  @opts              = opts
  @mock_functions    = config['functions']
  @before_conditions = config['before']
  @after_conditions  = config['after']
  @strict_variables  = opts[:strict_variables] ? 'yes' : 'no'

  # Initialise all of the classes and nodes
  config['classes'].each { |clarse| Onceover::Class.new(clarse) } unless config['classes'] == nil
  @classes = Onceover::Class.all

  config['nodes'].each { |node| Onceover::Node.new(node) } unless config['nodes'] == nil
  @nodes = Onceover::Node.all

  # Add the 'all_classes' and 'all_nodes' default groups
  @node_groups  << Onceover::Group.new('all_nodes', @nodes)
  @class_groups << Onceover::Group.new('all_classes', @classes)

  # Initialise all of the groups
  config['node_groups'].each { |name, members| @node_groups << Onceover::Group.new(name, members) } unless config['node_groups'] == nil
  config['class_groups'].each { |name, members| @class_groups << Onceover::Group.new(name, members) } unless config['class_groups'] == nil

  @filter_tags    = opts[:tags]      ? [opts[:tags].split(',')].flatten : nil
  @filter_classes = opts[:classes]   ? [opts[:classes].split(',')].flatten.map {|x| Onceover::Class.find(x)} : nil
  @filter_nodes   = opts[:nodes]     ? [opts[:nodes].split(',')].flatten.map {|x| Onceover::Node.find(x)} : nil
  @skip_r10k      = opts[:skip_r10k] ? true : false
  @force          = opts[:force] || false

  # Validate the mock_functions
  if @mock_functions && @mock_functions.any? { |name, details| details.has_key? 'type' }
    logger.warn "The 'type' key for mocked functions is deprecated and will be ignored, please remove it."
  end

  # Loop over all of the items in the test matrix and add those as test
  # objects to the list of tests
  config['test_matrix'].each do |test_hash|
    test_hash.each do |machines, settings|
      if settings['tests'] == 'spec'
        @spec_tests << Onceover::Test.new(machines, settings['classes'], settings)
      elsif settings['tests'] == 'acceptance'
        @acceptance_tests << Onceover::Test.new(machines, settings['classes'], settings)
      elsif settings['tests'] == 'all_tests'
        tst = Onceover::Test.new(machines,settings['classes'],settings)
        @spec_tests << tst
        @acceptance_tests << tst
      end
    end
  end
end