-
Notifications
You must be signed in to change notification settings - Fork 260
/
Copy pathdatadog_agent_integrations_apache_spec.rb
125 lines (105 loc) · 3.93 KB
/
datadog_agent_integrations_apache_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
require 'spec_helper'
describe 'datadog_agent::integrations::apache' 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/apache.yaml'
else
"#{CONF_DIR}/apache.d/conf.yaml"
end
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('datadog_agent') }
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).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) }
it { is_expected.to contain_file(conf_file).without_content(%r{tags:}) }
it { is_expected.to contain_file(conf_file).without_content(%r{apache_user:}) }
it { is_expected.to contain_file(conf_file).without_content(%r{apache_password:}) }
end
context 'with parameters set' do
let(:params) do
{
url: 'http://foobar',
username: 'userfoo',
password: 'passfoo',
tags: ['foo', 'bar', 'baz'],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
it { is_expected.to contain_file(conf_file).with_content(%r{apache_user: userfoo}) }
it { is_expected.to contain_file(conf_file).with_content(%r{apache_password: passfoo}) }
end
context 'with tags parameter single value' do
let(:params) do
{
tags: 'foo',
}
end
it { is_expected.not_to compile }
skip 'this is currently unimplemented behavior' do
it { is_expected.to contain_file(conf_file).with_content(%r{tags:\s+- foo\s*?[^-]}m) }
end
end
context 'with tags parameter array' do
let(:params) do
{
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
{
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
context 'with instances hash' do
let(:params) do
{
instances: [
{
'apache_status_url' => 'http://foobar',
'apache_user' => 'userfoo',
'apache_password' => 'passfoo',
'tags' => ['foo', 'bar', 'baz'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
it { is_expected.to contain_file(conf_file).with_content(%r{apache_user: userfoo}) }
it { is_expected.to contain_file(conf_file).with_content(%r{apache_password: passfoo}) }
end
end
end
end
end