Class: PuppetUnitTests::TestData

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_unit_tests/test_data.rb

Overview

YAML test data.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, name, usecases) ⇒ TestData

Returns a new instance of TestData.



23
24
25
26
27
# File 'lib/puppet_unit_tests/test_data.rb', line 23

def initialize(type, name, usecases)
  @type = type
  @name = name
  @usecases = usecases
end

Instance Attribute Details

#facts ⇒ Object

Returns the value of attribute facts.



16
17
18
# File 'lib/puppet_unit_tests/test_data.rb', line 16

def facts
  @facts
end

#hiera ⇒ Object

Returns the value of attribute hiera.



19
20
21
# File 'lib/puppet_unit_tests/test_data.rb', line 19

def hiera
  @hiera
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/puppet_unit_tests/test_data.rb', line 13

def name
  @name
end

#server_facts ⇒ Object

Returns the value of attribute server_facts.



17
18
19
# File 'lib/puppet_unit_tests/test_data.rb', line 17

def server_facts
  @server_facts
end

#settings ⇒ Object

Returns the value of attribute settings.



20
21
22
# File 'lib/puppet_unit_tests/test_data.rb', line 20

def settings
  @settings
end

#stubs ⇒ Object

Returns the value of attribute stubs.



21
22
23
# File 'lib/puppet_unit_tests/test_data.rb', line 21

def stubs
  @stubs
end

#trusted_facts ⇒ Object

Returns the value of attribute trusted_facts.



18
19
20
# File 'lib/puppet_unit_tests/test_data.rb', line 18

def trusted_facts
  @trusted_facts
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/puppet_unit_tests/test_data.rb', line 12

def type
  @type
end

#usecases ⇒ Object (readonly)

Returns the value of attribute usecases.



14
15
16
# File 'lib/puppet_unit_tests/test_data.rb', line 14

def usecases
  @usecases
end

Class Method Details

.parse(path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/puppet_unit_tests/test_data.rb', line 30

def parse(path)
  dir = File.dirname(path)
  type = File.basename(dir)
  name = File.basename(path, ".yaml")
  data = YAML.load_file(path)
  usecases = data["usecases"].map do |dn, du|
    parse_usecase(dn, du, type)
  end
  td = new(type, name, usecases)
  td.facts = data["facts"] || {}
  td.server_facts = data["server_facts"] || {}
  td.trusted_facts = data["trusted_facts"] || {}
  td.hiera = data["hiera"] || {}
  td.settings = data["settings"] || {}
  td.stubs = data["stubs"] || []

  td
rescue UserDataError => e
  e.path = path
  raise e
end

Instance Method Details

#check(env) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/puppet_unit_tests/test_data.rb', line 65

def check(env)
  hiera_data = { "global" => @hiera }
  errors = {}
  @usecases.each do |uc|
    Puppet.runtime[:facter].clear
    hiera_data["usecase"] = uc.hiera
    Thread.current[:hiera_data] = hiera_data

    uc_errors = check_usecase(env, uc)
    next if uc_errors.empty?

    errors[uc.name] = uc_errors
  end

  errors
end