|
2 | 2 | require 'stringio'
|
3 | 3 |
|
4 | 4 | describe Puppet::Type.type(:package).provider(:openbsd) do
|
| 5 | + include PuppetSpec::Fixtures |
| 6 | + |
5 | 7 | let(:package) { Puppet::Type.type(:package).new(:name => 'bash', :provider => 'openbsd') }
|
6 | 8 | let(:provider) { described_class.new(package) }
|
7 | 9 |
|
|
15 | 17 | before :each do
|
16 | 18 | # Stub some provider methods to avoid needing the actual software
|
17 | 19 | # installed, so we can test on whatever platform we want.
|
| 20 | + #allow(Puppet::Util).to receive(:which).with("pkg_info").and_return("/usr/sbin/pkg_info") |
18 | 21 | allow(described_class).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info')
|
19 | 22 | allow(described_class).to receive(:command).with(:pkgadd).and_return('/usr/sbin/pkg_add')
|
20 | 23 | allow(described_class).to receive(:command).with(:pkgdelete).and_return('/usr/sbin/pkg_delete')
|
21 |
| - |
22 |
| - allow(Puppet::FileSystem).to receive(:exist?) |
23 | 24 | end
|
24 | 25 |
|
25 | 26 | context "#instances" do
|
26 | 27 | it "should return nil if execution failed" do
|
| 28 | + allow(described_class).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info') |
27 | 29 | expect(provider).to receive(:pkginfo).and_raise(Puppet::ExecutionFailure, 'wawawa')
|
| 30 | + #expect(provider).to receive(:pkginfo).with(['-a', '-z']) |
28 | 31 | expect(described_class.instances).to be_nil
|
29 | 32 | end
|
30 | 33 |
|
|
43 | 46 |
|
44 | 47 | it "should return all flavors if set" do
|
45 | 48 | fixture = File.read(my_fixture('pkginfo.list'))
|
46 |
| - expect(described_class).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -a -z}).and_yield(fixture) |
| 49 | + expect(provider).to receive(:pkgadd).with(['-a', '-z']).and_yield(fixture) |
47 | 50 | instances = described_class.instances.map {|p| {:name => p.get(:name),
|
48 | 51 | :ensure => p.get(:ensure), :flavor => p.get(:flavor)}}
|
49 |
| - expect(instances.size).to eq(2) |
| 52 | + expect(instances.size).to eq(5) |
50 | 53 | expect(instances[0]).to eq({:name => 'autoconf%2.13', :ensure => 'present', :flavor => nil})
|
51 | 54 | expect(instances[1]).to eq({:name => 'autoconf%2.56', :ensure => 'present', :flavor => nil})
|
52 | 55 | expect(instances[2]).to eq({:name => 'bash', :ensure => 'present', :flavor => nil})
|
|
64 | 67 | end
|
65 | 68 |
|
66 | 69 | context "#get_full_name" do
|
67 |
| - it "should return the full unversioned package name when updating with a flavor" do |
68 |
| - provider.resource[:ensure] = 'latest' |
| 70 | + it "should return the full unversioned package name when installing with a flavor" do |
| 71 | + provider.resource[:ensure] = 'present' |
69 | 72 | provider.resource[:flavor] = 'static'
|
70 | 73 | expect(provider.get_full_name).to eq('bash--static')
|
71 | 74 | end
|
72 | 75 |
|
73 |
| - it "should return the full unversioned package name when updating without a flavor" do |
74 |
| - provider.resource[:name] = 'puppet' |
75 |
| - provider.resource[:ensure] = 'latest' |
76 |
| - expect(provider.get_full_name).to eq('puppet--') |
| 76 | + it "should return the full unversioned package name when installing with a branch" do |
| 77 | + provider.resource[:name] = 'bash%stable' |
| 78 | + expect(provider.get_full_name).to eq('bash--%stable') |
77 | 79 | end
|
78 | 80 |
|
79 |
| - it "should use the ensure parameter if it is numeric" do |
80 |
| - provider.resource[:name] = 'zsh' |
81 |
| - provider.resource[:ensure] = '1.0' |
82 |
| - expect(provider.get_full_name).to eq('zsh-1.0') |
83 |
| - end |
84 |
| - |
85 |
| - it "should lookup the correct version" do |
86 |
| - output = 'bash-3.1.17 GNU Bourne Again Shell' |
87 |
| - expect(provider).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -I bash}).and_yield(output) |
88 |
| - expect(provider.get_full_name).to eq('bash-3.1.17') |
89 |
| - end |
90 |
| - |
91 |
| - it "should lookup the correction version with flavors" do |
92 |
| - provider.resource[:name] = 'fossil' |
93 |
| - provider.resource[:flavor] = 'static' |
94 |
| - output = 'fossil-1.29v0-static simple distributed software configuration management' |
95 |
| - expect(provider).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -I fossil}).and_yield(output) |
96 |
| - expect(provider.get_full_name).to eq('fossil-1.29v0-static') |
| 81 | + it "should return the full unversioned package name when installing without a flavor" do |
| 82 | + provider.resource[:name] = 'puppet' |
| 83 | + expect(provider.get_full_name).to eq('puppet--') |
97 | 84 | end
|
98 |
| - end |
99 | 85 |
|
100 |
| - context "#get_version" do |
101 |
| - it "should return nil if execution fails" do |
102 |
| - expect(provider).to receive(:execpipe).and_raise(Puppet::ExecutionFailure, 'wawawa') |
103 |
| - expect(provider.get_version).to be_nil |
| 86 | + it "should return unversioned package name when installing without flavor or branch" do |
| 87 | + expect(provider.get_full_name).to eq('bash--') |
104 | 88 | end
|
105 | 89 |
|
106 |
| - it "should return the package version if in the output" do |
107 |
| - output = 'bash-3.1.17 GNU Bourne Again Shell' |
108 |
| - expect(provider).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -I bash}).and_yield(output) |
109 |
| - expect(provider.get_version).to eq('3.1.17') |
| 90 | + it "should return the full unversioned package name when installing with branch and flavor" do |
| 91 | + provider.resource[:name] = 'postfix%stable' |
| 92 | + provider.resource[:flavor] = 'ldap-mysql' |
| 93 | + expect(provider.get_full_name).to eq('postfix--ldap-mysql%stable') |
110 | 94 | end
|
111 | 95 |
|
112 |
| - it "should return the empty string if the package is not present" do |
113 |
| - provider.resource[:name] = 'zsh' |
114 |
| - expect(provider).to receive(:execpipe).with(%w{/usr/sbin/pkg_info -I zsh}).and_yield(StringIO.new('')) |
115 |
| - expect(provider.get_version).to eq('') |
116 |
| - end |
117 | 96 | end
|
118 | 97 |
|
119 | 98 | context "#query" do
|
120 | 99 | it "should return the installed version if present" do
|
121 | 100 | fixture = File.read(my_fixture('pkginfo.detail'))
|
122 |
| - expect(provider).to receive(:pkginfo).with('bash').and_return(fixture) |
123 |
| - expect(provider.query).to eq({ :ensure => '3.1.17' }) |
| 101 | + #expect(provider).to receive(:pkginfo).with('bash').and_return(fixture) |
| 102 | + expect(provider.query).to eq({:branch=>nil, :ensure=>"present", :flavor=>nil, :name=>"bash", :provider=>:openbsd}) |
124 | 103 | end
|
125 | 104 |
|
126 | 105 | it "should return nothing if not present" do
|
127 | 106 | provider.resource[:name] = 'zsh'
|
128 |
| - expect(provider).to receive(:pkginfo).with('zsh').and_return('') |
129 | 107 | expect(provider.query).to be_nil
|
130 | 108 | end
|
131 | 109 | end
|
|
152 | 130 | end
|
153 | 131 |
|
154 | 132 | context "#uninstall_options" do
|
155 |
| - it "should return nill by default" do |
156 |
| - expect(provider.uninstall_options).to be_nil |
| 133 | + it "should return empty array by default" do |
| 134 | + expect(provider.uninstall_options).to eq([]) |
157 | 135 | end
|
158 | 136 |
|
159 | 137 | it "should return uninstall_options when set" do
|
|
175 | 153 | context "#uninstall" do
|
176 | 154 | describe 'when uninstalling' do
|
177 | 155 | it 'should use erase to purge' do
|
178 |
| - expect(provider).to receive(:pkgdelete).with('-c', '-q', 'bash') |
| 156 | + expect(provider).to receive(:pkgdelete).with('-c', '-qq', [], 'bash--') |
179 | 157 | provider.purge
|
180 | 158 | end
|
181 | 159 | end
|
182 | 160 |
|
183 | 161 | describe 'with uninstall_options' do
|
184 | 162 | it 'should use uninstall_options as Array' do
|
185 | 163 | provider.resource[:uninstall_options] = ['-q', '-c']
|
186 |
| - expect(provider).to receive(:pkgdelete).with(['-q', '-c'], 'bash') |
| 164 | + expect(provider).to receive(:pkgdelete).with(['-q', '-c'], 'bash--') |
187 | 165 | provider.uninstall
|
188 | 166 | end
|
189 | 167 | end
|
|
198 | 176 | expect(provider.flavor).to eq('no_x11-python')
|
199 | 177 | end
|
200 | 178 |
|
201 |
| - it 'should remove and install the new flavor if different' do |
| 179 | + it 'should reinstall the new flavor if different' do |
202 | 180 | provider.resource[:flavor] = 'no_x11-ruby'
|
203 |
| - expect(provider).to receive(:uninstall).ordered |
204 | 181 | expect(provider).to receive(:install).ordered
|
205 | 182 | provider.flavor = provider.resource[:flavor]
|
206 | 183 | end
|
|
0 commit comments