-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathdatadog_agent_integrations_http_check_spec.rb
235 lines (215 loc) · 11.1 KB
/
datadog_agent_integrations_http_check_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
229
230
231
232
233
234
235
require 'spec_helper'
describe 'datadog_agent::integrations::http_check' do
ALL_SUPPORTED_AGENTS.each do |agent_major_version|
context 'supported agents' do
let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" }
conf_file = if agent_major_version == 5
'/etc/dd-agent/conf.d/http_check.yaml'
else
"#{CONF_DIR}/http_check.d/conf.yaml"
end
it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_file(conf_file).with(
owner: DD_USER,
group: DD_GROUP,
mode: PERMISSIONS_PROTECTED_FILE,
)
}
it { is_expected.to contain_file(conf_file).that_requires("Package[#{PACKAGE_NAME}]") }
it { is_expected.to contain_file(conf_file).that_notifies("Service[#{SERVICE_NAME}]") }
context 'with default parameters' do
it { is_expected.to contain_file(conf_file).without_content(%r{name: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{url: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{username: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{password: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{timeout: 1}) }
it { is_expected.to contain_file(conf_file).without_content(%r{data: }) }
it { is_expected.to contain_file(conf_file).without_content(%(threshold: )) }
it { is_expected.to contain_file(conf_file).without_content(%r{window: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{content_match: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{reverse_content_match: true}) }
it { is_expected.to contain_file(conf_file).without_content(%r{include_content: true}) }
it { is_expected.to contain_file(conf_file).without_content(%r{collect_response_time: true}) }
it { is_expected.to contain_file(conf_file).without_content(%r{http_response_status_code: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{disable_ssl_validation: false}) }
it { is_expected.to contain_file(conf_file).without_content(%r{skip_event: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{no_proxy: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{check_certificate_expiration: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{days_warning: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{days_critical: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{headers: }) }
it { is_expected.to contain_file(conf_file).without_content(%r{tags: }) }
end
context 'with parameters set' do
let(:params) do
{
sitename: 'foo.bar.baz',
url: 'http://foo.bar.baz:4096',
username: 'foouser',
password: 'barpassword',
timeout: 123,
method: 'post',
min_collection_interval: 30,
data: 'key=value',
threshold: 456,
window: 789,
content_match: 'foomatch',
reverse_content_match: true,
include_content: true,
collect_response_time: false,
disable_ssl_validation: true,
skip_event: true,
http_response_status_code: 503,
no_proxy: true,
check_certificate_expiration: true,
days_warning: 14,
days_critical: 7,
allow_redirects: true,
ca_certs: '/dev/null',
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{name: foo.bar.baz}) }
it { is_expected.to contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:4096}) }
it { is_expected.to contain_file(conf_file).with_content(%r{username: foouser}) }
it { is_expected.to contain_file(conf_file).with_content(%r{password: barpassword}) }
it { is_expected.to contain_file(conf_file).with_content(%r{timeout: 123}) }
it { is_expected.to contain_file(conf_file).with_content(%r{method: post}) }
it { is_expected.to contain_file(conf_file).with_content(%r{min_collection_interval: 30}) }
it { is_expected.to contain_file(conf_file).with_content(%r{data: key=value}) }
it { is_expected.to contain_file(conf_file).with_content(%r{threshold: 456}) }
it { is_expected.to contain_file(conf_file).with_content(%r{window: 789}) }
it { is_expected.to contain_file(conf_file).with_content(%r{content_match: foomatch}) }
it { is_expected.to contain_file(conf_file).with_content(%r{reverse_content_match: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{include_content: true}) }
it { is_expected.to contain_file(conf_file).without_content(%r{collect_response_time: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{disable_ssl_validation: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{skip_event: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{http_response_status_code: 503}) }
it { is_expected.to contain_file(conf_file).with_content(%r{no_proxy: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{check_certificate_expiration: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{days_warning: 14}) }
it { is_expected.to contain_file(conf_file).with_content(%r{days_critical: 7}) }
it { is_expected.to contain_file(conf_file).with_content(%r{allow_redirects: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{ca_certs: "/dev/null"}) }
end
context 'with json post data' do
let(:params) do
{
sitename: 'foo.bar.baz',
url: 'http://foo.bar.baz:4096',
method: 'post',
data: ['key: value'],
headers: ['Content-Type: application/json'],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{method: post}) }
it { is_expected.to contain_file(conf_file).with_content(%r{data:\s+key:\s+value}) }
it { is_expected.to contain_file(conf_file).with_content(%r{headers:\s+Content-Type:\s+application/json}) }
end
context 'with tags parameter array' do
let(:params) do
{
sitename: 'foo.bar.baz',
url: 'http://foo.bar.baz:4096',
tags: ['foo', 'bar', 'baz'],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{tags:\s+- foo\s+- bar\s+- baz\s*?[^-]}m) }
end
context 'with tags parameter empty values' do
context 'mixed in with other tags' do
let(:params) do
{
sitename: 'foo.bar.baz',
url: 'http://foo.bar.baz:4096',
tags: ['foo', '', 'baz'],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{tags:\s+- foo\s+- baz\s*?[^-]}m) }
end
context 'single element array of an empty string' do
let(:params) do
{
tags: [''],
}
end
skip('undefined behavior')
end
context 'single value empty string' do
let(:params) do
{
tags: '',
}
end
skip('doubly undefined behavior')
end
end
context 'with contact set' do
let(:params) do
{
contact: %r{alice bob carlo},
}
end
# the parameter is '$contact' and the template uses '@contacts', so neither is used
skip 'this functionality appears to not be functional' do
it { is_expected.to contain_file(conf_file).with_content(%r{notify:\s+- alice\s+bob\s+carlo}) }
end
end
context 'with instances hash' do
let(:params) do
{
instances: [
{
'name' => 'foo.bar.baz',
'url' => 'http://foo.bar.baz:4096',
'username' => 'foouser',
'password' => 'barpassword',
'timeout' => 123,
'method' => 'post',
'data' => 'key=value',
'threshold' => 456,
'window' => 789,
'content_match' => 'foomatch',
'reverse_content_match' => true,
'include_content' => true,
'collect_response_time' => false,
'disable_ssl_validation' => true,
'skip_event' => true,
'http_response_status_code' => 503,
'no_proxy' => true,
'check_certificate_expiration' => true,
'days_warning' => 14,
'days_critical' => 7,
'allow_redirects' => true,
'ca_certs' => '/dev/null',
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{name: foo.bar.baz}) }
it { is_expected.to contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:4096}) }
it { is_expected.to contain_file(conf_file).with_content(%r{username: foouser}) }
it { is_expected.to contain_file(conf_file).with_content(%r{password: barpassword}) }
it { is_expected.to contain_file(conf_file).with_content(%r{timeout: 123}) }
it { is_expected.to contain_file(conf_file).with_content(%r{method: post}) }
it { is_expected.to contain_file(conf_file).with_content(%r{data: key=value}) }
it { is_expected.to contain_file(conf_file).with_content(%r{threshold: 456}) }
it { is_expected.to contain_file(conf_file).with_content(%r{window: 789}) }
it { is_expected.to contain_file(conf_file).with_content(%r{content_match: foomatch}) }
it { is_expected.to contain_file(conf_file).with_content(%r{reverse_content_match: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{include_content: true}) }
it { is_expected.to contain_file(conf_file).without_content(%r{collect_response_time: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{disable_ssl_validation: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{skip_event: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{http_response_status_code: 503}) }
it { is_expected.to contain_file(conf_file).with_content(%r{no_proxy: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{check_certificate_expiration: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{days_warning: 14}) }
it { is_expected.to contain_file(conf_file).with_content(%r{days_critical: 7}) }
it { is_expected.to contain_file(conf_file).with_content(%r{allow_redirects: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{ca_certs: "/dev/null"}) }
end
end
end
end