-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
init_spec.rb
234 lines (199 loc) · 7.5 KB
/
init_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
# frozen_string_literal: true
require 'spec_helper'
describe 'borg' do
let :node do
'rspec.puppet.com'
end
on_supported_os.each do |os, facts|
context "on #{os}" do
let :facts do
facts.merge({ systemd: true })
end
let :params do
{
backupserver: 'localhost'
}
end
context 'with all defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_file('/etc/borg') }
it { is_expected.to contain_file('/etc/profile.d/borg.sh') }
it { is_expected.to contain_file('/usr/local/bin/borg-backup') }
it { is_expected.to contain_file('/usr/local/bin/borg_exporter') }
it { is_expected.to contain_file('/etc/borg-restore.cfg') }
it { is_expected.to contain_class('borg::install') }
it { is_expected.to contain_class('borg::config') }
it { is_expected.to contain_class('borg::service') }
it { is_expected.to contain_ssh__client__config__user('root') }
it { is_expected.to contain_ssh_keygen('root_borg') }
it { is_expected.to contain_exec('ssh_keygen-root_borg') }
it { is_expected.to contain_systemd__unit_file('borg-backup.timer') }
it { is_expected.to contain_systemd__unit_file('borg-backup.service').without_content(%r{Requires=}) }
it { is_expected.to contain_systemd__unit_file('borg-backup.service').with_content(%r{Wants=network-online.target}) }
it { is_expected.to contain_systemd__unit_file('borg-backup.service').with_content(%r{After=network-online.target}) }
end
context 'with requires and no wants/after dependencies' do
let :params do
{
requires: ['foo'],
wants: [],
after: [],
backupserver: 'localhost',
}
end
it { is_expected.to contain_systemd__unit_file('borg-backup.service').with_content(%r{Requires=foo}) }
it { is_expected.to contain_systemd__unit_file('borg-backup.service').without_content(%r{Wants=}) }
it { is_expected.to contain_systemd__unit_file('borg-backup.service').without_content(%r{After=}) }
end
case facts[:os]['name']
when 'Archlinux'
context 'on Archlinux' do
it { is_expected.to contain_package('borg') }
it { is_expected.to contain_package('perl-app-borgrestore') }
end
when 'Ubuntu'
context 'on Ubuntu' do
it { is_expected.to contain_package('borgbackup') }
it { is_expected.to contain_package('borgbackup-doc') }
it { is_expected.to contain_package('gcc') }
it { is_expected.to contain_package('make') }
it { is_expected.to contain_package('cpanminus') }
it { is_expected.to contain_package('libdbd-sqlite3-perl') }
it { is_expected.to contain_apt__ppa('ppa:costamagnagianfranco/borgbackup') } if facts[:os]['release']['major'] == '16.04'
end
when 'RedHat', 'CentOS'
context 'on osfamily Redhat' do
it { is_expected.to contain_package('gcc') }
it { is_expected.to contain_package('perl-core') }
it { is_expected.to contain_exec('install_borg_restore') }
it { is_expected.to contain_file('/opt/BorgRestore') }
it { is_expected.to contain_file('/usr/local/bin/borg-restore.pl') }
if facts[:os]['release']['major'].to_i == 8
it { is_expected.not_to contain_package('perl-TAP-Harness-Env') }
it { is_expected.to contain_package('perl-App-cpanminus') }
else
it { is_expected.to contain_package('perl-TAP-Harness-Env') }
it { is_expected.not_to contain_package('perl-App-cpanminus') }
end
end
when 'Gentoo'
context 'on osfamily Gentoo' do
it { is_expected.to contain_package('App-cpanminus') }
end
end
context 'with keep intervall set to 0' do
let :params do
{
keep_yearly: 0,
keep_monthly: 0,
keep_weekly: 0,
keep_daily: 0,
keep_within: 0,
backupserver: 'localhost'
}
end
it { is_expected.to compile.with_all_deps }
end
context 'fails without backupserver' do
let :params do
{}
end
it { is_expected.not_to compile }
end
context 'without manage_package' do
let :params do
{
backupserver: 'localhost',
manage_package: false
}
end
it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('borgbackup') }
end
context 'with ssh_key_type set to rsa' do
let :params do
{
backupserver: 'localhost',
ssh_key_type: 'rsa'
}
end
it { is_expected.to compile.with_all_deps }
end
context 'fails without a valid backuptime present' do
let :params do
{
backupserver: 'localhost',
backuptime: ''
}
end
it { is_expected.not_to compile }
end
context 'with nondefault backuptime present' do
let :params do
{
backupserver: 'localhost',
backuptime: { 'default' => '01:00:00' }
}
end
it { is_expected.to compile.with_all_deps }
end
context 'with multiple backuptimes present' do
let :params do
{
backupserver: 'localhost',
backuptime: { '1 am' => '01:00:00', '2 am' => '02:00:00' }
}
end
it { is_expected.to compile.with_all_deps }
end
context 'without nondefault compression present' do
let :params do
{
backupserver: 'localhost',
compression: 'auto,zstd,6'
}
end
it { is_expected.to contain_file('/usr/local/bin/borg-backup').with_content(%r{^\s+--compression "auto,zstd,6"$}) }
end
context 'without manage_prune' do
let :params do
{
backupserver: 'localhost',
manage_prune: false
}
end
it { is_expected.not_to contain_file('/usr/local/bin/borg-backup').with_content(%r{/^\s+borg prune/}) }
end
context 'with absolute backup destination dir present' do
let :params do
{
backupserver: 'localhost',
create_prometheus_metrics: true,
absolutebackupdestdir: '/some/other/path'
}
end
it { is_expected.to contain_file('/etc/borg').with_content(%r{^REPOSITORY=backup:/some/other/path$}) }
it { is_expected.to contain_file('/etc/profile.d/borg.sh').with_content(%r{^export BORG_REPO=backup:/some/other/path$}) }
it { is_expected.to contain_file('/usr/local/bin/borg-backup').with_content(%r{^\s*borg_repo="backup:/some/other/path"$}) }
end
context 'with additional excludes' do
let :params do
{
backupserver: 'localhost',
additional_excludes: ['/path with/spaces']
}
end
it { is_expected.to contain_file('/usr/local/bin/borg-backup').with_content(%r{^\s*"/path with/spaces"$}) }
end
context 'without exclude_pattern' do
let :params do
{
backupserver: 'localhost',
exclude_pattern: ['sh:/some/path/*']
}
end
it { is_expected.to contain_file('/usr/local/bin/borg-backup').with_content(%r{^sh:/some/path/\*$}) }
end
end
end
end