X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fclasses%2Fapt_update_spec.rb;h=c6336a9151c943347f4029eff026dc7a881cedbc;hb=7e31732abd277c852564c10011099bdf6967dc4f;hp=d0bfae26759d0c4e7203c396c7781f8b987a1473;hpb=d6ac23f77796fef37be8173f6574c61091aa82b0;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index d0bfae2..c6336a9 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -1,107 +1,201 @@ -#!/usr/bin/env rspec +# frozen_string_literal: true + require 'spec_helper' -describe 'apt::update', :type => :class do - context 'when apt::always_apt_update is true' do - #This should completely disable all of this logic. These tests are to guarantee that we don't somehow magically change the behavior. - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let (:pre_condition) { "class{'::apt': always_apt_update => true}" } - 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 }) - end - ['always','daily','weekly','reluctantly'].each do |update_frequency| - context "when apt::apt_update_frequency has the value of #{update_frequency}" 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 } } - let (:pre_condition) { "class{'::apt': always_apt_update => true, 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}) - end - end - context 'when $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let (:pre_condition) { "class{'::apt': always_apt_update => true, 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}) - end - end +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: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + 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) do + { + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + 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 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: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, + apt_update_last_success: factval, + } + end + let(:pre_condition) { "class{ '::apt': update => {'frequency' => 'reluctantly' },}" } - context 'when apt::always_apt_update is false' do - context "and apt::apt_update_frequency has the value of 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 } } - let (:pre_condition) { "class{'::apt': always_apt_update => false, 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}) - end + 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' } } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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}) - end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) do + { + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + 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 - context "and apt::apt_update_frequency has the value of 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} } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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}) + end + ['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: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + 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 $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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 the $::apt_update_last_success fact has a recent value' do + let(:facts) do + { + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, + apt_update_last_success: Time.now.to_i, + } end - end - end - ['daily','weekly'].each do |update_frequency| - context "and apt::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 } } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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}) - end - 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 - context 'when the $::apt_update_last_success fact has a recent value' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => Time.now.to_i } } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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}) - end + end + context 'when $::apt_update_last_success is nil' do + let(:facts) do + { + os: { + family: 'Debian', + name: 'Debian', + release: { + major: '8', + full: '8.0', + }, + distro: { + codename: 'jessie', + id: 'Debian', + }, + }, + apt_update_last_success: nil, + } end - context 'when $::apt_update_last_success is nil' do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian' } } - let (:pre_condition) { "class{ '::apt': always_apt_update => false, 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}) - 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