Class: PuppetUnitTests::TestUsecase

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

Overview

A test usecase.

Direct Known Subclasses

ClassUsecase, DefineUsecase, FunctionUsecase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ TestUsecase

Returns a new instance of TestUsecase.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet_unit_tests/test_usecase.rb', line 21

def initialize(name)
  @name = name

  @facts = {}
  @server_facts = {}
  @trusted_facts = {}
  @hiera = {}
  @settings = {}

  @present = []
  @absent = []
  @error = nil
end

Instance Attribute Details

#absent ⇒ Object

Returns the value of attribute absent.



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

def absent
  @absent
end

#error ⇒ Object

Returns the value of attribute error.



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

def error
  @error
end

#facts ⇒ Object

Returns the value of attribute facts.



11
12
13
# File 'lib/puppet_unit_tests/test_usecase.rb', line 11

def facts
  @facts
end

#hiera ⇒ Object

Returns the value of attribute hiera.



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

def hiera
  @hiera
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/puppet_unit_tests/test_usecase.rb', line 9

def name
  @name
end

#present ⇒ Object

Returns the value of attribute present.



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

def present
  @present
end

#server_facts ⇒ Object

Returns the value of attribute server_facts.



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

def server_facts
  @server_facts
end

#settings ⇒ Object

Returns the value of attribute settings.



15
16
17
# File 'lib/puppet_unit_tests/test_usecase.rb', line 15

def settings
  @settings
end

#trusted_facts ⇒ Object

Returns the value of attribute trusted_facts.



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

def trusted_facts
  @trusted_facts
end

Class Method Details

.parse(name, data_usecase) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/puppet_unit_tests/test_usecase.rb', line 36

def parse(name, data_usecase)
  uc = new(name)
  return uc unless data_usecase

  uc.facts = data_usecase["facts"] || {}
  uc.server_facts = data_usecase["server_facts"] || {}
  uc.trusted_facts = data_usecase["trusted_facts"] || {}
  uc.hiera = data_usecase["hiera"] || {}
  uc.settings = data_usecase["settings"] || {}

  uc.error = data_usecase["error"]
  if data_usecase.key?("present")
    uc.present = data_usecase["present"].map do |rs|
      ResourceSpec.parse(rs)
    end
  end
  if data_usecase.key?("absent")
    uc.absent = data_usecase["absent"].map do |rs|
      ResourceSpec.parse(rs)
    end
  end

  uc
end