apt_update_spec.rb 4.7 KB

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