Merge pull request #515 from mhaskel/merge_2.0.x_to_master
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_update_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe 'apt::update', :type => :class do
5   context "and apt::update['frequency']='always'" do
6     { 'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
7       context "and $::apt_update_last_success indicates #{desc}" do
8         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => '3.5.0', } }
9         let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" }
10         it 'should trigger an apt-get update run' do
11           #set the apt_update exec's refreshonly attribute to false
12           is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
13         end
14       end
15     end
16     context 'when $::apt_update_last_success is nil' do
17       let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => '3.5.0', } }
18       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
19       it 'should trigger an apt-get update run' do
20         #set the apt_update exec\'s refreshonly attribute to false
21         is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
22       end
23     end
24   end
25   context "and apt::update['frequency']='reluctantly'" do
26     {'a recent run' => Time.now.to_i, 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
27       context "and $::apt_update_last_success indicates #{desc}" do
28         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => '3.5.0',} }
29         let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
30         it 'should not trigger an apt-get update run' do
31           #don't change the apt_update exec's refreshonly attribute. (it should be true)
32           is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
33         end
34       end
35     end
36     context 'when $::apt_update_last_success is nil' do
37       let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion   => '3.5.0', } }
38       let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
39       it 'should not trigger an apt-get update run' do
40         #don't change the apt_update exec's refreshonly attribute. (it should be true)
41         is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
42       end
43     end
44   end
45   ['daily','weekly'].each do |update_frequency|
46     context "and apt::update['frequency'] has the value of #{update_frequency}" do
47       { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
48         context "and $::apt_update_last_success indicates #{desc}" do
49           let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion   => '3.5.0', } }
50           let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
51           it 'should trigger an apt-get update run' do
52             #set the apt_update exec\'s refreshonly attribute to false
53             is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
54           end
55         end
56       end
57       context 'when the $::apt_update_last_success fact has a recent value' do
58         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i, :puppetversion   => '3.5.0', } }
59         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
60         it 'should not trigger an apt-get update run' do
61           #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
62           is_expected.to contain_exec('apt_update').with({'refreshonly' => true})
63         end
64       end
65       context 'when $::apt_update_last_success is nil' do
66         let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil, :puppetversion   => '3.5.0', } }
67         let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
68         it 'should trigger an apt-get update run' do
69           #set the apt_update exec\'s refreshonly attribute to false
70           is_expected.to contain_exec('apt_update').with({'refreshonly' => false})
71         end
72       end
73     end
74   end
75 end