-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathalertmanager_spec.rb
169 lines (149 loc) · 5.33 KB
/
alertmanager_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
# frozen_string_literal: true
require 'spec_helper'
describe 'prometheus::alertmanager' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:facts) do
facts.merge(os_specific_facts(facts))
end
context 'with version specified' do
let(:params) do
{
version: '0.27.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url'
}
end
describe 'with specific params' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_archive('/tmp/alertmanager-0.27.0.tar.gz') }
it { is_expected.to contain_class('prometheus') }
it { is_expected.to contain_group('alertmanager') }
it { is_expected.to contain_user('alertmanager') }
it { is_expected.to contain_prometheus__daemon('alertmanager') }
it { is_expected.to contain_service('alertmanager') }
end
describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/alertmanager').with('target' => '/opt/alertmanager-0.27.0.linux-amd64/alertmanager') }
end
describe 'config file contents' do
it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Service[alertmanager]')
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', ['---', 'global:', ' smtp_smarthost: localhost:25', ' smtp_from: alertmanager@localhost'])
}
end
describe 'service reload' do
it {
expect(subject).to contain_exec('alertmanager-reload').with(
# 'command' => 'systemctl reload alertmanager',
'path' => ['/usr/bin', '/bin', '/usr/sbin', '/sbin'],
'refreshonly' => true
)
}
end
end
context 'with latest version specified and mute_time_intervals' do
let(:params) do
{
version: '0.27.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url',
mute_time_intervals: [
{ 'name' => 'weekend', 'time_intervals' => [{ 'weekdays' => %w[saturday sunday] }] }
],
}
end
it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
'mute_time_intervals:',
'- name: weekend',
' time_intervals:',
' - weekdays:',
' - saturday',
' - sunday',
])
}
end
context 'with latest version specified and time_intervals' do
let(:params) do
{
version: '0.27.0',
arch: 'amd64',
os: 'linux',
bin_dir: '/usr/local/bin',
install_method: 'url',
mute_time_intervals: [
{ 'name' => 'weekend', 'time_intervals' => [{ 'weekdays' => %w[saturday sunday] }] }
],
time_intervals: [
{ 'name' => 'weekend', 'time_intervals' => [{ 'weekdays' => %w[saturday sunday] }] }
],
}
end
it { is_expected.to contain_file('/etc/alertmanager/alertmanager.yaml').without(content: %r{mute_time_intervals}) }
it {
verify_contents(catalogue, '/etc/alertmanager/alertmanager.yaml', [
'time_intervals:',
'- name: weekend',
' time_intervals:',
' - weekdays:',
' - saturday',
' - sunday',
])
}
end
context 'when reload_on_change => true' do
let(:params) { { reload_on_change: true } }
it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_notify('Exec[alertmanager-reload]')
}
end
context 'with manage_config => false' do
[
{
version: '0.27.0',
manage_config: false
}
].each do |parameters|
context "with alertmanager verions #{parameters[:version]}" do
let(:params) do
parameters
end
it {
expect(subject).not_to contain_file('/etc/alertmanager/alertmanager.yaml')
}
end
end
end
context 'with validate_config => false' do
let(:params) do
{
manage_config: true,
install_method: 'package',
validate_config: false,
}
end
it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').without_validate_cmd
}
end
context 'with validate_config => true' do
let(:params) do
{
manage_config: true,
install_method: 'package',
validate_config: true,
bin_dir: '/bin',
}
end
it {
expect(subject).to contain_file('/etc/alertmanager/alertmanager.yaml').with_validate_cmd('/bin/amtool check-config --alertmanager.url=\'\' %')
}
end
end
end
end