forked from puppetlabs/puppetlabs-mysql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_backup_spec.rb
73 lines (65 loc) · 2.13 KB
/
mysql_backup_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
require 'spec_helper_acceptance'
describe 'mysql::server::backup class', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
context 'should work with no errors' do
it 'when configuring mysql backups' do
pp = <<-EOS
class { 'mysql::server': root_password => 'password' }
mysql::db { [
'backup1',
'backup2'
]:
user => 'backup',
password => 'secret',
}
package { 'bzip2':
ensure => present,
}
class { 'mysql::server::backup':
backupuser => 'myuser',
backuppassword => 'mypassword',
backupdir => '/tmp/backups',
backupcompress => true,
postscript => [
'rm -rf /var/tmp/mysqlbackups',
'rm -f /var/tmp/mysqlbackups.done',
'cp -r /tmp/backups /var/tmp/mysqlbackups',
'touch /var/tmp/mysqlbackups.done',
],
execpath => '/usr/bin:/usr/sbin:/bin:/sbin:/opt/zimbra/bin',
require => Package['bzip2'],
}
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stderr).to eq("")
end
end
end
describe 'mysqlbackup.sh' do
it 'should run mysqlbackup.sh with no errors' do
shell("/usr/local/sbin/mysqlbackup.sh") do |r|
expect(r.stderr).to eq("")
end
end
it 'should dump all databases to single file' do
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
expect(r.stdout).to match(/1/)
expect(r.exit_code).to be_zero
end
end
context 'should create one file per database per run' do
it 'executes mysqlbackup.sh a second time' do
shell('sleep 1')
shell('/usr/local/sbin/mysqlbackup.sh')
end
it 'creates at least one backup tarball' do
shell('ls -l /tmp/backups/mysql_backup_*-*.sql.bz2 | wc -l') do |r|
expect(r.stdout).to match(/2/)
expect(r.exit_code).to be_zero
end
end
end
end
end