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
15 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
18 apt_update_last_success: factval,
19 lsbdistcodename: 'jessie',
22 let(:pre_condition) do
23 "class{'::apt': update => {'frequency' => 'always' },}"
26 it 'triggers an apt-get update run' do
27 # set the apt_update exec's refreshonly attribute to false
28 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
32 context 'when $::apt_update_last_success is nil' do
35 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
38 lsbdistcodename: 'jessie',
41 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
43 it 'triggers an apt-get update run' do
44 # set the apt_update exec\'s refreshonly attribute to false
45 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
49 context "when apt::update['frequency']='reluctantly'" do
51 'a recent run' => Time.now.to_i,
52 'we are due for a run' => 1_406_660_561,
53 'the update-success-stamp file does not exist' => -1,
54 }.each_pair do |desc, factval|
55 context "when $::apt_update_last_success indicates #{desc}" do
58 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
61 apt_update_last_success: factval,
62 lsbdistcodename: 'jessie',
65 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
67 it 'does not trigger an apt-get update run' do
68 # don't change the apt_update exec's refreshonly attribute. (it should be true)
69 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
73 context 'when $::apt_update_last_success is nil' do
76 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
79 lsbdistcodename: 'jessie',
82 let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
84 it 'does not trigger an apt-get update run' do
85 # don't change the apt_update exec's refreshonly attribute. (it should be true)
86 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
90 ['daily', 'weekly'].each do |update_frequency|
91 context "when apt::update['frequency'] has the value of #{update_frequency}" do
92 { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
93 context "when $::apt_update_last_success indicates #{desc}" do
96 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
99 apt_update_last_success: factval,
100 lsbdistcodename: 'jessie',
103 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
105 it 'triggers an apt-get update run' do
106 # set the apt_update exec\'s refreshonly attribute to false
107 is_expected.to contain_exec('apt_update').with('refreshonly' => false)
111 context 'when the $::apt_update_last_success fact has a recent value' do
114 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
117 lsbdistcodename: 'jessie',
118 apt_update_last_success: Time.now.to_i,
121 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
123 it 'does not trigger an apt-get update run' do
124 # don't change the apt_update exec\'s refreshonly attribute. (it should be true)
125 is_expected.to contain_exec('apt_update').with('refreshonly' => true)
128 context 'when $::apt_update_last_success is nil' do
131 os: { family: 'Debian', name: 'Debian', release: { major: '8', full: '8.0' } },
134 lsbdistcodename: 'jessie',
135 apt_update_last_success: nil,
138 let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
140 it 'triggers an apt-get update run' do
141 # set the apt_update exec\'s refreshonly attribute to false
142 is_expected.to contain_exec('apt_update').with('refreshonly' => false)