1 # frozen_string_literal: true
5 describe 'apt::update', type: :class do
6 context "when apt::update['frequency']='always'" do
8 'a recent run' => Time.now.to_i,
9 'we are due for a run' => 1_406_660_561,
10 'the update-success-stamp file does not exist' => -1,
11 }.each_pair do |desc, factval|
12 context "when $::apt_update_last_success indicates #{desc}" do
27 apt_update_last_success: factval,
30 let(:pre_condition) do
31 "class{'::apt': update => {'frequency' => 'always' },}"
34 it 'triggers an apt-get update run' do
35 # set the apt_update exec's refreshonly attribute to false
36 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
40 context 'when $::apt_update_last_success is nil' do
57 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
59 it 'triggers an apt-get update run' do
60 # set the apt_update exec\'s refreshonly attribute to false
61 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
64 context 'and Exec[apt_update] refreshonly is overridden to true and has recent run' do
79 apt_update_last_success: Time.now.to_i,
82 let(:pre_condition) do
84 class{'::apt': update => {'frequency' => 'always' },}
85 Exec <| title=='apt_update' |> { refreshonly => true }
89 it 'skips an apt-get update run' do
90 # set the apt_update exec's refreshonly attribute to false
91 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
95 context "when apt::update['frequency']='reluctantly'" do
97 'a recent run' => Time.now.to_i,
98 'we are due for a run' => 1_406_660_561,
99 'the update-success-stamp file does not exist' => -1,
100 }.each_pair do |desc, factval|
101 context "when $::apt_update_last_success indicates #{desc}" do
116 apt_update_last_success: factval,
119 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
121 it 'does not trigger an apt-get update run' do
122 # don't change the apt_update exec's refreshonly attribute. (it should be true)
123 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
127 context 'when $::apt_update_last_success is nil' do
144 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
146 it 'does not trigger an apt-get update run' do
147 # don't change the apt_update exec's refreshonly attribute. (it should be true)
148 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
152 ['daily', 'weekly'].each do |update_frequency|
153 context "when apt::update['frequency'] has the value of #{update_frequency}" do
154 { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
155 context "when $::apt_update_last_success indicates #{desc}" do
170 apt_update_last_success: factval,
173 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
175 it 'triggers an apt-get update run' do
176 # set the apt_update exec\'s refreshonly attribute to false
177 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
181 context 'when the $::apt_update_last_success fact has a recent value' do
196 apt_update_last_success: Time.now.to_i,
199 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
201 it 'does not trigger an apt-get update run' do
202 # don't change the apt_update exec\'s refreshonly attribute. (it should be true)
203 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
206 context 'when $::apt_update_last_success is nil' do
221 apt_update_last_success: nil,
224 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
226 it 'triggers an apt-get update run' do
227 # set the apt_update exec\'s refreshonly attribute to false
228 is_expected.to contain_exec('apt_update').with('refreshonly' => false)