1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
require 'spec_helper'
require 'matchers/include_in_order'
require 'puppet_spec/compiler'
require 'puppet/indirector/catalog/compiler'
describe "A catalog" do
include PuppetSpec::Compiler
shared_examples_for "when compiled" do
context "when transmitted to the agent" do
it "preserves the order in which the resources are added to the catalog" do
resources_in_declaration_order = ["Class[First]",
"Second[position]",
"Class[Third]",
"Fourth[position]"]
master_catalog, agent_catalog = master_and_agent_catalogs_for(<<-EOM)
define fourth() { }
class third { }
define second() {
fourth { "position": }
}
class first {
second { "position": }
class { "third": }
}
include first
EOM
expect(resources_in(master_catalog)).
to include_in_order(*resources_in_declaration_order)
expect(resources_in(agent_catalog)).
to include_in_order(*resources_in_declaration_order)
end
it "does not contain unrealized, virtual resources" do
virtual_resources = ["Unrealized[unreal]", "Class[Unreal]"]
master_catalog, agent_catalog = master_and_agent_catalogs_for(<<-EOM)
class unreal { }
define unrealized() { }
class real {
@unrealized { "unreal": }
@class { "unreal": }
}
include real
EOM
expect(resources_in(master_catalog)).to_not include(*virtual_resources)
expect(resources_in(agent_catalog)).to_not include(*virtual_resources)
end
it "does not contain unrealized, exported resources" do
exported_resources = ["Unrealized[unreal]", "Class[Unreal]"]
master_catalog, agent_catalog = master_and_agent_catalogs_for(<<-EOM)
class unreal { }
define unrealized() { }
class real {
@@unrealized { "unreal": }
@@class { "unreal": }
}
include real
EOM
expect(resources_in(master_catalog)).to_not include(*exported_resources)
expect(resources_in(agent_catalog)).to_not include(*exported_resources)
end
end
end
describe 'using classic parser' do
before :each do
Puppet[:parser] = 'current'
end
it_behaves_like 'when compiled' do
end
it "compiles resource creation from appended array as two separate resources" do
# moved here from acceptance test "jeff_append_to_array.rb"
master_catalog = master_catalog_for(<<-EOM)
class parent {
$arr1 = [ "parent array element" ]
}
class parent::child inherits parent {
$arr1 += ["child array element"]
notify { $arr1: }
}
include parent::child
EOM
expect(resources_in(master_catalog)).to include('Notify[parent array element]', 'Notify[child array element]')
end
end
describe 'using future parser' do
before :each do
Puppet[:parser] = 'future'
end
it_behaves_like 'when compiled' do
end
end
def master_catalog_for(manifest)
master_catalog = Puppet::Resource::Catalog::Compiler.new.filter(compile_to_catalog(manifest))
end
def master_and_agent_catalogs_for(manifest)
compiler = Puppet::Resource::Catalog::Compiler.new
master_catalog = compiler.filter(compile_to_catalog(manifest))
agent_catalog = Puppet::Resource::Catalog.convert_from(:pson, master_catalog.render(:pson))
[master_catalog, agent_catalog]
end
def resources_in(catalog)
catalog.resources.map(&:ref)
end
end
|