/
objects_spec.rb
228 lines (194 loc) · 5.68 KB
/
objects_spec.rb
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require 'spec_helper'
facts = {
:kernel => 'Linux',
:os => {:family => 'Debian', :name => 'Debian'},
:osfamily => 'Debian' }
describe('icinga2::object', :type => :define) do
let(:title) do
'foo'
end
let(:pre_condition) do
[
"class { 'icinga2': }"
]
end
before(:each) do
# Fake assert_private function from stdlib to not fail within this test
Puppet::Parser::Functions.newfunction(:assert_private, :type => :rvalue) { |args| }
end
on_supported_os.each do |os, complete_facts|
let(:facts) do
complete_facts
end
context "#{os} with object_type => 'foobar'" do
let(:params) do
{
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
case facts[:osfamily]
when 'Debian'
before(:each) do
@icinga2_user = 'root'
@icinga2_group = 'nagios'
end
when 'Windows'
before(:each) do
@icinga2_user = null
@icinga2_group = null
end
else
before(:each) do
@icinga2_user = 'root'
@icinga2_group = 'icinga'
end
end
it { is_expected.to contain_concat('/bar/baz')
.with({
'owner' => @icinga2_user,
'group' => @icinga2_group
}).that_notifies('Class[icinga2::service]') }
it { is_expected.to contain_concat__fragment('foo')
.with({
'target' => '/bar/baz',
'order' => '10'
}).with_content(/object foobar "foo" \{/) }
it { should compile }
end
end
let(:facts) do
facts
end
context "with template => true" do
let(:params) do
{
:template => true,
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/template foobar "foo" \{/) }
end
context "with import => ['bar', 'baz']" do
let(:params) do
{
:import => ['bar', 'baz'],
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/import "bar"\n import "baz"\n/) }
end
context "with apply_target => 'Service', object_type => 'Service' (same value)" do
let(:params) do
{
:apply_target => 'Service',
:object_type => 'Service',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to raise_error(Puppet::Error, /must be different/) }
end
context "with apply => true, apply_target => 'Host'" do
let(:params) do
{
:apply => true,
:apply_target => 'Host',
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/apply foobar \"foo\" to Host \{/) }
end
context "with apply => true, apply_target => 'Service'" do
let(:params) do
{
:apply => true,
:apply_target => 'Service',
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/apply foobar \"foo\" to Service \{/) }
end
context "with apply => 'item in array', prefix => true" do
let(:params) do
{
:apply => 'item in array',
:prefix => true,
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/apply foobar \"foo\" for \(item in array\) \{/) }
end
context "with apply => 'key => value in hash', prefix => 'some string'" do
let(:params) do
{
:apply => 'key => value in hash',
:prefix => 'some string',
:object_type => 'foobar',
:target => '/bar/baz',
:order => '10'
}
end
it { is_expected.to contain_concat__fragment('foo')
.with_content(/apply foobar \"some string\" for \(key => value in hash\) \{/) }
end
end
on_icinga_objects = {
'ApiUser' => 'icinga2::object::apiuser',
'CheckCommand' => 'icinga2::object::checkcommand',
'Dependency' => 'icinga2::object::dependency',
'Endpoint' => 'icinga2::object::endpoint',
'EventCommand' => 'icinga2::object::eventcommand',
'Host' => 'icinga2::object::host',
'HostGroup' => 'icinga2::object::hostgroup',
'Notification' => 'icinga2::object::notification',
'NotificationCommand' => 'icinga2::object::notificationcommand',
'ScheduledDowntime' => 'icinga2::object::scheduleddowntime',
'Service' => 'icinga2::object::service',
'ServiceGroup' => 'icinga2::object::servicegroup',
'TimePeriod' => 'icinga2::object::timeperiod',
'User' => 'icinga2::object::user',
'UserGroup' => 'icinga2::object::usergroup',
'Zone' => 'icinga2::object::zone',
}
on_icinga_objects.each do |otype, rtype|
describe(rtype, :type => :define) do
let(:title) do
'foo'
end
let(:pre_condition) do
[
"class { 'icinga2': }"
]
end
let(:facts) do
facts
end
context "with all defaults" do
let(:params) do
{
:target => '/bar/baz'
}
end
it { is_expected.to contain_icinga2__object("icinga2::object::#{otype}::foo")
.with_object_type(otype) }
it { should compile }
end
end
end