apt_update_spec.rb 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env rspec
  2. require 'spec_helper'
  3. describe 'apt::update', :type => :class do
  4. context 'when apt::always_apt_update is true' do
  5. #This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior.
  6. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  7. let (:pre_condition) { "class{'::apt': always_apt_update => true}" }
  8. it 'should trigger an apt-get update run' do
  9. #set the apt_update exec's refreshonly attribute to false
  10. should contain_exec('apt_update').with({'refreshonly' => false })
  11. end
  12. ['always','daily','weekly','reluctantly'].each do |update_frequency|
  13. context "when apt::apt_update_frequency has the value of #{update_frequency}" do
  14. { '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|
  15. context "and $::apt_update_last_success indicates #{desc}" do
  16. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
  17. let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" }
  18. it 'should trigger an apt-get update run' do
  19. # set the apt_update exec's refreshonly attribute to false
  20. should contain_exec('apt_update').with({'refreshonly' => false})
  21. end
  22. end
  23. context 'when $::apt_update_last_success is nil' do
  24. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  25. let (:pre_condition) { "class{'::apt': always_apt_update => true, apt_update_frequency => '#{update_frequency}' }" }
  26. it 'should trigger an apt-get update run' do
  27. #set the apt_update exec\'s refreshonly attribute to false
  28. should contain_exec('apt_update').with({'refreshonly' => false})
  29. end
  30. end
  31. end
  32. end
  33. end
  34. end
  35. context 'when apt::always_apt_update is false' do
  36. context "and apt::apt_update_frequency has the value of always" do
  37. { '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|
  38. context "and $::apt_update_last_success indicates #{desc}" do
  39. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
  40. let (:pre_condition) { "class{'::apt': always_apt_update => false, apt_update_frequency => 'always' }" }
  41. it 'should trigger an apt-get update run' do
  42. #set the apt_update exec's refreshonly attribute to false
  43. should contain_exec('apt_update').with({'refreshonly' => false})
  44. end
  45. end
  46. end
  47. context 'when $::apt_update_last_success is nil' do
  48. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  49. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'always' }" }
  50. it 'should trigger an apt-get update run' do
  51. #set the apt_update exec\'s refreshonly attribute to false
  52. should contain_exec('apt_update').with({'refreshonly' => false})
  53. end
  54. end
  55. end
  56. context "and apt::apt_update_frequency has the value of reluctantly" do
  57. {'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|
  58. context "and $::apt_update_last_success indicates #{desc}" do
  59. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval} }
  60. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" }
  61. it 'should not trigger an apt-get update run' do
  62. #don't change the apt_update exec's refreshonly attribute. (it should be true)
  63. should contain_exec('apt_update').with({'refreshonly' => true})
  64. end
  65. end
  66. end
  67. context 'when $::apt_update_last_success is nil' do
  68. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  69. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => 'reluctantly' }" }
  70. it 'should not trigger an apt-get update run' do
  71. #don't change the apt_update exec's refreshonly attribute. (it should be true)
  72. should contain_exec('apt_update').with({'refreshonly' => true})
  73. end
  74. end
  75. end
  76. ['daily','weekly'].each do |update_frequency|
  77. context "and apt::apt_update_frequency has the value of #{update_frequency}" do
  78. { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
  79. context "and $::apt_update_last_success indicates #{desc}" do
  80. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval } }
  81. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" }
  82. it 'should trigger an apt-get update run' do
  83. #set the apt_update exec\'s refreshonly attribute to false
  84. should contain_exec('apt_update').with({'refreshonly' => false})
  85. end
  86. end
  87. end
  88. context 'when the $::apt_update_last_success fact has a recent value' do
  89. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } }
  90. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" }
  91. it 'should not trigger an apt-get update run' do
  92. #don't change the apt_update exec\'s refreshonly attribute. (it should be true)
  93. should contain_exec('apt_update').with({'refreshonly' => true})
  94. end
  95. end
  96. context 'when $::apt_update_last_success is nil' do
  97. let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } }
  98. let (:pre_condition) { "class{ '::apt': always_apt_update => false, apt_update_frequency => '#{update_frequency}' }" }
  99. it 'should trigger an apt-get update run' do
  100. #set the apt_update exec\'s refreshonly attribute to false
  101. should contain_exec('apt_update').with({'refreshonly' => false})
  102. end
  103. end
  104. end
  105. end
  106. end
  107. end