Skip to content

Commit

Permalink
(maint) increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
h0tw1r3 committed May 9, 2024
1 parent dfcae9b commit 915caa1
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ spec/spec_helper.rb:
spec_overrides:
- require 'spec_helper_local'
coverage_report: true
minimum_code_coverage_percentage: 69
minimum_code_coverage_percentage: 81

.github/workflows/ci.yml:
unmanaged: true
Expand Down
19 changes: 19 additions & 0 deletions spec/classes/mysql_backup_mysqldump_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ class { 'mysql::server': }
minute: 5,
)
}

it {
is_expected.to contain_package('bzip2')
}

it {
package_name = (facts[:os]['family'] == 'RedHat') ? 'cronie' : 'cron'
is_expected.to contain_package(package_name)
}
end

context 'without backupcomress' do
let(:params) do
{ 'backupcompress' => false, }.merge(default_params)
end

it {
is_expected.not_to contain_package('bzip2')
}
end

context 'with compression_command' do
Expand Down
51 changes: 31 additions & 20 deletions spec/classes/mysql_backup_xtrabackup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
describe 'mysql::backup::xtrabackup' do
on_supported_os.each do |os, facts|
context "on #{os}" do
let(:package) do
if facts[:os]['family'] == 'RedHat'
if Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '8') >= 0
'percona-xtrabackup-24'
else
'percona-xtrabackup'
end
elsif facts[:os]['name'] == 'Debian'
'percona-xtrabackup-24'
elsif facts[:os]['name'] == 'Ubuntu'
if Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '20') < 0 &&
Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '16') >= 0
'percona-xtrabackup'
else
'percona-xtrabackup-24'
end
elsif facts[:os]['family'] == 'Suse'
'xtrabackup'
else
'percona-xtrabackup'
end
end

let(:pre_condition) do
<<-MANIFEST
class { 'mysql::server': }
Expand Down Expand Up @@ -38,26 +61,7 @@ class { 'mysql::server': }
)
end

package = if facts[:os]['family'] == 'RedHat'
if Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '8') >= 0
'percona-xtrabackup-24'
else
'percona-xtrabackup'
end
elsif facts[:os]['name'] == 'Debian'
'percona-xtrabackup-24'
elsif facts[:os]['name'] == 'Ubuntu'
if Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '20') < 0 &&
Puppet::Util::Package.versioncmp(facts[:os]['release']['major'], '16') >= 0
'percona-xtrabackup'
else
'percona-xtrabackup-24'
end
elsif facts[:os]['family'] == 'Suse'
'xtrabackup'
else
'percona-xtrabackup'
end
it { is_expected.to contain_package(package) }

it 'contains the weekly cronjob' do
is_expected.to contain_cron('xtrabackup-weekly')
Expand All @@ -72,6 +76,11 @@ class { 'mysql::server': }
.that_requires("Package[#{package}]")
end

it {
package_name = (facts[:os]['family'] == 'RedHat') ? 'cronie' : 'cron'
is_expected.to contain_package(package_name)
}

it 'contains the daily cronjob for weekdays 1-6' do
dateformat = case facts[:os]['name']
when 'FreeBSD', 'OpenBSD'
Expand Down Expand Up @@ -304,6 +313,8 @@ class { 'mysql::server': }
%r{(\n*^mariabackup\s+.*\$@)},
)
end

it { is_expected.to contain_package(params[:backupmethod_package]) }
end

context 'with backup_success_file_path' do
Expand Down
2 changes: 2 additions & 0 deletions spec/classes/mysql_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
it { is_expected.to contain_class('mysql::client::install') }
it { is_expected.not_to contain_class('mysql::bindings') }
it { is_expected.to contain_package('mysql_client') }
it { is_expected.to contain_anchor('mysql::client::start') }
it { is_expected.to contain_anchor('mysql::client::end') }
end

context 'with bindings enabled' do
Expand Down
15 changes: 15 additions & 0 deletions spec/classes/mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
it { is_expected.to contain_class('mysql::server::providers') }
it { is_expected.to contain_file('mysql-config-file').that_comes_before('Service[mysqld]') }
it { is_expected.not_to contain_file('mysql-config-file').that_notifies('Service[mysqld]') }

it { is_expected.to contain_anchor('mysql::server::start') }
it { is_expected.to contain_anchor('mysql::server::end') }

it {
is_expected.to contain_exec('wait_for_mysql_socket_to_open')
.with(
command: ['test', '-S', %r{.*\.sock}],
unless: [['test', '-S', %r{.*\.sock}]],
tries: '3',
try_sleep: '10',
require: 'Service[mysqld]',
path: '/bin:/usr/bin',
)
}
end

context 'with remove_default_accounts set' do
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end
c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
c.after(:suite) do
RSpec::Puppet::Coverage.report!(69)
RSpec::Puppet::Coverage.report!(81)
end

# Filter backtrace noise
Expand Down

0 comments on commit 915caa1

Please sign in to comment.