(GH-iac-334) Remove code specific to unsupported OSs
[puppet-modules/puppetlabs-apt.git] / spec / classes / apt_update_spec.rb
index 8fba4a0c98860e57bb2d7b948c8436cd59aab616..0db9a470b20394edea2b7e8cb9f78dd7e88877e0 100644 (file)
-#!/usr/bin/env rspec
+# frozen_string_literal: true
+
 require 'spec_helper'
 
-describe 'apt::update', :type => :class do
-  context "and apt::update['frequency']='always'" do
-    { '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|
-      context "and $::apt_update_last_success indicates #{desc}" do
-        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
-        let (:pre_condition) { "class{'::apt': update => {'frequency' => 'always' },}" }
-        it 'should trigger 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})
+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: '9',
+                full: '9.0',
+              },
+              distro: {
+                codename: 'stretch',
+                id: 'Debian',
+              },
+            },
+            apt_update_last_success: factval,
+          }
+        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) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
-      let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'always' },}" }
-      it 'should trigger 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})
+      let(:facts) do
+        {
+          os: {
+            family: 'Debian',
+            name: 'Debian',
+            release: {
+              major: '9',
+              full: '9.0',
+            },
+            distro: {
+              codename: 'stretch',
+              id: 'Debian',
+            },
+          },
+        }
+      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
+    context 'and Exec[apt_update] refreshonly is overridden to true and has recent run' do
+      let(:facts) do
+        {
+          os: {
+            family: 'Debian',
+            name: 'Debian',
+            release: {
+              major: '9',
+              full: '9.0',
+            },
+            distro: {
+              codename: 'stretch',
+              id: 'Debian',
+            },
+          },
+          apt_update_last_success: Time.now.to_i,
+        }
+      end
+      let(:pre_condition) do
+        "
+        class{'::apt': update => {'frequency' => 'always' },}
+        Exec <| title=='apt_update' |> { refreshonly => true }
+        "
+      end
+
+      it 'skips 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' => true)
       end
     end
   end
-  context "and apt::update['frequency']='reluctantly'" do
-    {'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|
-      context "and $::apt_update_last_success indicates #{desc}" do
-        let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy'} }
-        let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
-        it 'should 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})
+  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: '9',
+                full: '9.0',
+              },
+              distro: {
+                codename: 'stretch',
+                id: 'Debian',
+              },
+            },
+            apt_update_last_success: factval,
+          }
+        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) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy' } }
-      let (:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" }
-      it 'should 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})
+      let(:facts) do
+        {
+          os: {
+            family: 'Debian',
+            name: 'Debian',
+            release: {
+              major: '9',
+              full: '9.0',
+            },
+            distro: {
+              codename: 'stretch',
+              id: 'Debian',
+            },
+          },
+        }
+      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
-  ['daily','weekly'].each do |update_frequency|
-    context "and apt::update['frequency'] has the value of #{update_frequency}" do
-      { 'we are due for a run' => 1406660561,'the update-success-stamp file does not exist' => -1 }.each_pair do |desc, factval|
-        context "and $::apt_update_last_success indicates #{desc}" do
-          let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy' } }
-          let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
-          it 'should trigger 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})
+  ['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: '9',
+                  full: '9.0',
+                },
+                distro: {
+                  codename: 'stretch',
+                  id: 'Debian',
+                },
+              },
+              apt_update_last_success: factval,
+            }
+          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) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => Time.now.to_i } }
-        let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
-        it 'should 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})
+        let(:facts) do
+          {
+            os: {
+              family: 'Debian',
+              name: 'Debian',
+              release: {
+                major: '9',
+                full: '9.0',
+              },
+              distro: {
+                codename: 'stretch',
+                id: 'Debian',
+              },
+            },
+            apt_update_last_success: Time.now.to_i,
+          }
+        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) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :apt_update_last_success => nil } }
-        let (:pre_condition) { "class{ '::apt': update => {'frequency' => '#{update_frequency}',} }" }
-        it 'should trigger 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})
+        let(:facts) do
+          {
+            os: {
+              family: 'Debian',
+              name: 'Debian',
+              release: {
+                major: '9',
+                full: '9.0',
+              },
+              distro: {
+                codename: 'stretch',
+                id: 'Debian',
+              },
+            },
+            apt_update_last_success: nil,
+          }
+        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