diff --git a/manifests/init.pp b/manifests/init.pp index 8b84305..d7d7d32 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -43,7 +43,9 @@ include pe_databases::postgresql_settings::table_settings } } - if defined('$manage_database_backups') { + # Because this parameter is a value of undef with a data type of Undef, + # We can the NotUndef type to determine if the value has been set + if $manage_database_backups =~ NotUndef { class { 'pe_databases::backup': disable_maintenance => ! $manage_database_backups, } diff --git a/spec/acceptance/backup_spec.rb b/spec/acceptance/backup_spec.rb index 276bc90..b164a73 100644 --- a/spec/acceptance/backup_spec.rb +++ b/spec/acceptance/backup_spec.rb @@ -11,10 +11,4 @@ class { 'pe_databases': # Run it twice and test for idempotency idempotent_apply(pp) end - it 'checks if backup cron jobs are up' do - run_shell('crontab -l -u pe-postgres') do |r| - expect(r.stdout).to match(%r{pe-activity, pe-classifier, pe-inventory, pe-orchestrator, pe-postgres, pe-rbac}) - expect(r.stdout).to match(%r{pe-puppetdb}) - end - end end diff --git a/spec/classes/backup_spec.rb b/spec/classes/backup_spec.rb new file mode 100644 index 0000000..c43c969 --- /dev/null +++ b/spec/classes/backup_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe 'pe_databases::backup' do + context 'when backing up tables' do + let(:pre_condition) { 'include pe_databases' } + + it { + # I have no idea how this works, but these are the resources we should end up with + is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-activity, pe-classifier, pe-inventory, pe-orchestrator, pe-postgres, pe-rbac]') + is_expected.to contain_cron('puppet_enterprise_database_backup_[pe-puppetdb]') + } + end +end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index f00799f..a8308cf 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -1,14 +1,6 @@ require 'spec_helper' describe 'pe_databases' do - let(:params) do - { - manage_database_backups: false, - manage_postgresql_settings: false, - manage_table_settings: false, - } - end - on_supported_os.each do |os, os_facts| context "on #{os}" do let(:facts) { os_facts } @@ -32,4 +24,14 @@ it { is_expected.to contain_notify('pe_databases_systemd_warn') } end + + context 'backups are not included by default' do + it { is_expected.not_to contain_class('pe_databases::backup') } + end + + context 'backups are included if configured' do + let(:params) { { manage_database_backups: true } } + + it { is_expected.to contain_class('pe_databases::backup') } + end end