X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=spec%2Fclasses%2Fapt_update_spec.rb;h=c46771a52d8b226a22101dd005e3c98a96970c96;hb=refs%2Fheads%2Ftrusted-contributors;hp=89ba942aac702dd2dd9f5d5e970db97c7fd5e1e0;hpb=6fa24e6b09cf988b897b2b5dc9b911770c0c71b7;p=puppet-modules%2Fpuppetlabs-apt.git diff --git a/spec/classes/apt_update_spec.rb b/spec/classes/apt_update_spec.rb index 89ba942..c46771a 100644 --- a/spec/classes/apt_update_spec.rb +++ b/spec/classes/apt_update_spec.rb @@ -5,26 +5,26 @@ 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, + '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 + context "when $apt_update_last_success indicates #{desc}" do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: factval, + apt_update_last_success: factval } end let(:pre_condition) do @@ -33,50 +33,51 @@ describe 'apt::update', type: :class do 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end end - context 'when $::apt_update_last_success is nil' do + context 'when $apt_update_last_success is nil' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, - }, + 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) + expect(subject).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 + + context 'when Exec[apt_update] refreshonly is overridden to true and has recent run' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: Time.now.to_i, + apt_update_last_success: Time.now.to_i } end let(:pre_condition) do @@ -88,144 +89,148 @@ describe 'apt::update', type: :class do 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) 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, + '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 + context "when $apt_update_last_success indicates #{desc}" do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: factval, + 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end end - context 'when $::apt_update_last_success is nil' do + context 'when $apt_update_last_success is nil' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, - }, + 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end 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 + pair = { 'we are due for a run' => 1_406_660_561, 'the update-success-stamp file does not exist' => -1 } + pair.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', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: factval, + 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end end - context 'when the $::apt_update_last_success fact has a recent value' do + 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', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: Time.now.to_i, + 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => true) end end - context 'when $::apt_update_last_success is nil' do + + context 'when $apt_update_last_success is nil' do let(:facts) do { os: { family: 'Debian', name: 'Debian', release: { - major: '8', - full: '8.0', + major: '9', + full: '9.0' }, distro: { - codename: 'jessie', - id: 'Debian', - }, + codename: 'stretch', + id: 'Debian' + } }, - apt_update_last_success: nil, + 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) + expect(subject).to contain_exec('apt_update').with('refreshonly' => false) end end end