|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe Puppet::Type.type(:puppet_agent_end_run).provider(:puppet_agent_end_run) do |
| 4 | + let(:catalog) { Puppet::Resource::Catalog.new } |
| 5 | + |
| 6 | + before do |
| 7 | + allow(Facter).to receive(:value) |
| 8 | + end |
| 9 | + |
| 10 | + context 'when package_version is latest' do |
| 11 | + let(:resource) do |
| 12 | + Puppet::Type.type(:puppet_agent_end_run).new(:name => 'latest', :provider => :puppet_agent_end_run) |
| 13 | + end |
| 14 | + |
| 15 | + let(:agent_latest_package) do |
| 16 | + Puppet::Type.type(:package).new(:name => 'puppet-agent', :ensure => 'latest', :provider => :yum) |
| 17 | + end |
| 18 | + |
| 19 | + before do |
| 20 | + catalog.add_resource(agent_latest_package) |
| 21 | + resource.catalog = catalog |
| 22 | + end |
| 23 | + |
| 24 | + context 'with dev versions' do |
| 25 | + it 'does not stop the run if package is already latest' do |
| 26 | + catalog.resource('package', 'puppet-agent').parameters[:ensure].latest = '0:7.8.0.64.g6670bf40b-1.el8' |
| 27 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0.64') |
| 28 | + expect(Puppet::Application).not_to receive(:stop!) |
| 29 | + |
| 30 | + resource.provider.stop |
| 31 | + end |
| 32 | + |
| 33 | + it 'stops the run if the current and desired versions differ' do |
| 34 | + catalog.resource('package', 'puppet-agent').parameters[:ensure].latest = '0:7.8.0.64.g6670bf40b-1.el8' |
| 35 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0.32') |
| 36 | + expect(Puppet::Application).to receive(:stop!) |
| 37 | + |
| 38 | + resource.provider.stop |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + context 'with released versions' do |
| 43 | + it 'does not stop the run if package is already latest' do |
| 44 | + catalog.resource('package', 'puppet-agent').parameters[:ensure].latest = '7.8.0-1.el8' |
| 45 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0') |
| 46 | + expect(Puppet::Application).not_to receive(:stop!) |
| 47 | + |
| 48 | + resource.provider.stop |
| 49 | + end |
| 50 | + |
| 51 | + |
| 52 | + it 'stops the run if the current and desired versions differ' do |
| 53 | + catalog.resource('package', 'puppet-agent').parameters[:ensure].latest = '7.9.0-1.el8' |
| 54 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0') |
| 55 | + expect(Puppet::Application).to receive(:stop!) |
| 56 | + |
| 57 | + resource.provider.stop |
| 58 | + end |
| 59 | + end |
| 60 | + end |
| 61 | + |
| 62 | + context 'when package_version is present' do |
| 63 | + let(:resource) do |
| 64 | + Puppet::Type.type(:puppet_agent_end_run).new(:name => 'present', :provider => :puppet_agent_end_run) |
| 65 | + end |
| 66 | + |
| 67 | + it 'never stops the run' do |
| 68 | + expect(Puppet::Application).not_to receive(:stop!) |
| 69 | + resource.provider.stop |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context 'when package_version is a released version' do |
| 74 | + let(:resource) do |
| 75 | + Puppet::Type.type(:puppet_agent_end_run).new(:name => '7.8.0', :provider => :puppet_agent_end_run) |
| 76 | + end |
| 77 | + |
| 78 | + it 'does not stop the run if current and desired versions match' do |
| 79 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0') |
| 80 | + expect(Puppet::Application).not_to receive(:stop!) |
| 81 | + |
| 82 | + resource.provider.stop |
| 83 | + end |
| 84 | + |
| 85 | + it 'stops the run if current and desired versions do not match' do |
| 86 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.7.0') |
| 87 | + expect(Puppet::Application).to receive(:stop!) |
| 88 | + |
| 89 | + resource.provider.stop |
| 90 | + end |
| 91 | + end |
| 92 | + |
| 93 | + context 'when package_version is a nightly version' do |
| 94 | + let(:resource) do |
| 95 | + Puppet::Type.type(:puppet_agent_end_run).new(:name => '7.8.0.32', :provider => :puppet_agent_end_run) |
| 96 | + end |
| 97 | + |
| 98 | + it 'does not stop the run if current and desired versions match' do |
| 99 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0.32') |
| 100 | + expect(Puppet::Application).not_to receive(:stop!) |
| 101 | + |
| 102 | + resource.provider.stop |
| 103 | + end |
| 104 | + |
| 105 | + it 'stops the run if current and desired versions do not match' do |
| 106 | + allow(Facter).to receive(:value).with('aio_agent_version').and_return('7.8.0') |
| 107 | + expect(Puppet::Application).to receive(:stop!) |
| 108 | + |
| 109 | + resource.provider.stop |
| 110 | + end |
| 111 | + end |
| 112 | +end |
0 commit comments