summaryrefslogtreecommitdiff
path: root/code/environments/production/modules/apt/spec/classes/apt_update_spec.rb
blob: 675bbd2c9bd5eca9adee11484421891488a62df1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
require 'spec_helper'

describe 'apt::update', type: :class do
  context "when apt::update['frequency']='always'" do
    {
      'a recent run'                                 => Time.now.to_i,
      'we are due for a run'                         => 1_406_660_561,
      'the update-success-stamp file does not exist' => -1,
    }.each_pair do |desc, factval|
      context "when $::apt_update_last_success indicates #{desc}" do
        let(:facts) do
          {
            os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
            lsbdistid: 'Debian',
            osfamily: 'Debian',
            apt_update_last_success: factval,
            lsbdistcodename: 'wheezy',
            puppetversion: Puppet.version,
          }
        end
        let(:pre_condition) do
          "class{'::apt': update => {'frequency' => 'always' },}"
        end

        it 'triggers an apt-get update run' do
          # set the apt_update exec's refreshonly attribute to false
          is_expected.to contain_exec('apt_update').with('refreshonly' => false)
        end
      end
    end
    context 'when $::apt_update_last_success is nil' do
      let(:facts) do
        {
          os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
          lsbdistid: 'Debian',
          osfamily: 'Debian',
          lsbdistcodename: 'wheezy',
          puppetversion: Puppet.version,
        }
      end
      let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }

      it 'triggers an apt-get update run' do
        # set the apt_update exec\'s refreshonly attribute to false
        is_expected.to contain_exec('apt_update').with('refreshonly' => false)
      end
    end
  end
  context "when apt::update['frequency']='reluctantly'" do
    {
      'a recent run'                                 => Time.now.to_i,
      'we are due for a run'                         => 1_406_660_561,
      'the update-success-stamp file does not exist' => -1,
    }.each_pair do |desc, factval|
      context "when $::apt_update_last_success indicates #{desc}" do
        let(:facts) do
          {
            os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
            lsbdistid: 'Debian',
            osfamily: 'Debian',
            apt_update_last_success: factval,
            lsbdistcodename: 'wheezy',
            puppetversion: Puppet.version,
          }
        end
        let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }

        it 'does not trigger an apt-get update run' do
          # don't change the apt_update exec's refreshonly attribute. (it should be true)
          is_expected.to contain_exec('apt_update').with('refreshonly' => true)
        end
      end
    end
    context 'when $::apt_update_last_success is nil' do
      let(:facts) do
        {
          os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
          lsbdistid: 'Debian',
          osfamily: 'Debian',
          lsbdistcodename: 'wheezy',
          puppetversion: Puppet.version,
        }
      end
      let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }

      it 'does not trigger an apt-get update run' do
        # don't change the apt_update exec's refreshonly attribute. (it should be true)
        is_expected.to contain_exec('apt_update').with('refreshonly' => true)
      end
    end
  end
  %w[daily weekly].each do |update_frequency|
    context "when apt::update['frequency'] has the value of #{update_frequency}" do
      { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
        context "when $::apt_update_last_success indicates #{desc}" do
          let(:facts) do
            {
              os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
              lsbdistid: 'Debian',
              osfamily: 'Debian',
              apt_update_last_success: factval,
              lsbdistcodename: 'wheezy',
              puppetversion: Puppet.version,
            }
          end
          let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }

          it 'triggers an apt-get update run' do
            # set the apt_update exec\'s refreshonly attribute to false
            is_expected.to contain_exec('apt_update').with('refreshonly' => false)
          end
        end
      end
      context 'when the $::apt_update_last_success fact has a recent value' do
        let(:facts) do
          {
            os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
            lsbdistid: 'Debian',
            osfamily: 'Debian',
            lsbdistcodename: 'wheezy',
            apt_update_last_success: Time.now.to_i,
            puppetversion: Puppet.version,
          }
        end
        let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }

        it 'does not trigger an apt-get update run' do
          # don't change the apt_update exec\'s refreshonly attribute. (it should be true)
          is_expected.to contain_exec('apt_update').with('refreshonly' => true)
        end
      end
      context 'when $::apt_update_last_success is nil' do
        let(:facts) do
          {
            os: { family: 'Debian', name: 'Debian', release: { major: '7', full: '7.0' } },
            lsbdistid: 'Debian',
            osfamily: 'Debian',
            lsbdistcodename: 'wheezy',
            apt_update_last_success: nil,
            puppetversion: Puppet.version,
          }
        end
        let(:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }

        it 'triggers an apt-get update run' do
          # set the apt_update exec\'s refreshonly attribute to false
          is_expected.to contain_exec('apt_update').with('refreshonly' => false)
        end
      end
    end
  end
end