-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathdatadog_agent_integrations_mongo_spec.rb
More file actions
183 lines (163 loc) · 6.01 KB
/
datadog_agent_integrations_mongo_spec.rb
File metadata and controls
183 lines (163 loc) · 6.01 KB
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
require 'spec_helper'
describe 'datadog_agent::integrations::mongo' 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/mongo.yaml'
else
"#{CONF_DIR}/mongo.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).with_content(%r{- server: mongodb://localhost:27017}) }
it { is_expected.to contain_file(conf_file).without_content(%r{tags:}) }
end
context 'with one mongo host defined in hosts' do
let(:params) do
{
servers: [
{
'hosts' => ['localhost:27017'],
'username' => 'user',
'password' => 'pass',
'dbm' => true,
'database_autodiscovery' => { 'enabled' => true },
'reported_database_hostname' => 'mongohost',
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{- hosts:\s+- localhost:27017}) }
it { is_expected.to contain_file(conf_file).with_content(%r{username: user}) }
it { is_expected.to contain_file(conf_file).with_content(%r{password: pass}) }
it { is_expected.to contain_file(conf_file).with_content(%r{dbm: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{database_autodiscovery:\s+enabled: true}) }
it { is_expected.to contain_file(conf_file).with_content(%r{reported_database_hostname: mongohost}) }
end
context 'with one mongo' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '12345',
'tags' => ['foo', 'bar', 'baz'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz}) }
end
context 'with multiple mongos' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '34567',
'tags' => ['foo', 'bar'],
},
{
'host' => '127.0.0.2',
'port' => '45678',
'tags' => ['baz', 'bat'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:34567/\s+tags:\s+- foo\s+- bar}) }
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678/\s+tags:\s+- baz\s+- bat}) }
it { is_expected.to contain_file(conf_file).with_content(%r{server:.*127.0.0.1.*server:.*127.0.0.2}m) }
end
context 'with custom collections one mongos' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '12345',
'tags' => ['foo', 'bar', 'baz'],
'collections' => ['collection_1', 'collection_2'],
},
{
'host' => '127.0.0.2',
'port' => '45678',
'tags' => ['baz', 'bat'],
'collections' => ['collection_1', 'collection_2'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) }
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.2:45678/\s+tags:\s+- baz\s+- bat\s+collections:\s+- collection_1\s+- collection_2}) }
end
context 'with custom collections multiple mongo' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '12345',
'tags' => ['foo', 'bar', 'baz'],
'collections' => ['collection_1', 'collection_2'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+collections:\s+- collection_1\s+- collection_2}) }
end
context 'with additional metrics' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '12345',
'tags' => ['foo', 'bar', 'baz'],
'additional_metrics' => ['top'],
},
],
}
end
it { is_expected.to contain_file(conf_file).with_content(%r{server: mongodb://127.0.0.1:12345/\s+tags:\s+- foo\s+- bar\s+- baz\s+additional_metrics:\s+- top}) }
end
context 'without tags' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '12345',
},
],
}
end
it { is_expected.to compile }
end
context 'weird tags' do
let(:params) do
{
servers: [
{
'host' => '127.0.0.1',
'port' => '56789',
'tags' => 'word',
},
],
}
end
it { is_expected.not_to compile }
end
end
end
end