X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fclasses%2Fapt_update_spec.rb;h=e178d40f508ec7fe385e43514ae1ee1c8be70bda;hb=c7013c082891edae1543c6244f1f0719dae98d13;hp=d031104ddd2f3ce81c924f6a160543f13e8e9e29;hpb=3e64758ca720d5325d40e11bb8619675b6c0c75f;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index d031104..e178d40 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -1,73 +1,151 @@ #!/usr/bin/env rspec require 'spec_helper' -describe 'apt::update', :type => :class do +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| + { + '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 "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } - 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: '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) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } + 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 '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}) + + 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 "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| + { + '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 "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version,} } + 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 '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}) + + 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', :puppetversion => Puppet.version, } } + 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 '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}) + + 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| + %w[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| + { '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 "and $::apt_update_last_success indicates #{desc}" do - let(:facts) { { :lsbdistid => 'Debian', :osfamily => 'Debian', :apt_update_last_success => factval, :lsbdistcodename => 'wheezy', :puppetversion => Puppet.version, } } + 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 '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}) + + 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, :puppetversion => Puppet.version, } } + 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 '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}) + + 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, :puppetversion => Puppet.version, } } + 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 '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}) + + 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