From 3a4abe4f98d4c24989a1def59968cb49d1d26268 Mon Sep 17 00:00:00 2001 From: b4ldr Date: Mon, 22 Feb 2016 12:52:07 +0000 Subject: add options support fix ruby 1.9 hash correct --- spec/classes/unattended_upgrades_spec.rb | 115 +++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) (limited to 'spec') diff --git a/spec/classes/unattended_upgrades_spec.rb b/spec/classes/unattended_upgrades_spec.rb index d951a87..7bc7365 100644 --- a/spec/classes/unattended_upgrades_spec.rb +++ b/spec/classes/unattended_upgrades_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe 'unattended_upgrades' do let(:file_unattended) { '/etc/apt/apt.conf.d/50unattended-upgrades' } let(:file_periodic) { '/etc/apt/apt.conf.d/10periodic' } + let(:file_options) { '/etc/apt/apt.conf.d/10options' } let(:facts) { { osfamily: 'Debian', lsbdistid: 'Debian', @@ -30,6 +31,13 @@ describe 'unattended_upgrades' do ) } + it { + should contain_apt__conf('options').with( + require: 'Package[unattended-upgrades]', + notify_update: false, + ) + } + it { should create_file(file_unattended).with( owner: 'root', @@ -96,6 +104,23 @@ describe 'unattended_upgrades' do ensure: 'absent', ) } + it { + should create_file(file_options).with( + owner: 'root', + group: 'root', + mode: '0644', + ).with_content( + /^Dpkg::Options\s{/ + ).with_content( + /^\s+\"--force-confdef\";/ + ).with_content( + /^\s+\"--force-confold\";/ + ).without_content( + /\"--force-confnew\";/ + ).without_content( + /\"--force-confmiss\";/ + ) + } end context 'with defaults on Debian 6 Squeeze' do @@ -295,6 +320,12 @@ describe 'unattended_upgrades' do dl_limit: 70, random_sleep: 300, notify_update: true, + options: { + 'force_confdef' => false, + 'force_confold' => false, + 'force_confnew' => true, + 'force_confmiss' => true, + } } end it { should contain_package('unattended-upgrades') } @@ -311,6 +342,13 @@ describe 'unattended_upgrades' do ) } + it { + should contain_apt__conf('options').with( + require: 'Package[unattended-upgrades]', + notify_update: true, + ) + } + it { should create_file(file_unattended).with( owner: 'root', @@ -375,6 +413,23 @@ describe 'unattended_upgrades' do ) } + it { + should create_file(file_options).with( + owner: 'root', + group: 'root', + mode: '0644', + ).with_content( + /^Dpkg::Options\s{/ + ).without_content( + /"--force-confdef";/ + ).without_content( + /"--force-confold";/ + ).with_content( + /^\s+"--force-confnew";/ + ).with_content( + /^\s+"--force-confmiss";/ + ) + } it { should contain_apt__conf('auto-upgrades').with( ensure: 'absent', @@ -527,5 +582,65 @@ describe 'unattended_upgrades' do }.to raise_error(Puppet::Error, /not a boolean/) end end + context 'bad options[\'force_confdef\']' do + let :params do + { + options: { 'force_confdef' => 'foo' }, + } + end + it do + expect { + subject.call + }.to raise_error(Puppet::Error, /not a boolean/) + end + end + context 'bad options[\'force_confold\']' do + let :params do + { + options: { 'force_confold' => 'foo' }, + } + end + it do + expect { + subject.call + }.to raise_error(Puppet::Error, /not a boolean/) + end + end + context 'bad options[\'force_confnew\']' do + let :params do + { + options: { 'force_confnew' => 'foo' }, + } + end + it do + expect { + subject.call + }.to raise_error(Puppet::Error, /not a boolean/) + end + end + context 'bad options[\'force_confmiss\']' do + let :params do + { + options: { 'force_confmiss' => 'foo' }, + } + end + it do + expect { + subject.call + }.to raise_error(Puppet::Error, /not a boolean/) + end + end + context 'bad options[\'invalid_key\']' do + let :params do + { + options: { 'invalid_key' => true }, + } + end + it do + expect { + subject.call + }.to raise_error(Puppet::Error, /invalid_key not a valid key/) + end + end end end -- cgit v1.2.3