Skip to content

Commit 79db867

Browse files
committed
some spec fixtures
1 parent d97c38a commit 79db867

File tree

2 files changed

+31
-54
lines changed

2 files changed

+31
-54
lines changed

lib/puppet/provider/package/openbsd.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
These options should be specified as an array where each element is either a
1616
string or a hash."
1717

18-
commands :pkginfo => "pkg_info",
19-
:pkgadd => "pkg_add",
18+
commands :pkgadd => "pkg_add",
19+
:pkginfo => "pkg_info",
2020
:pkgdelete => "pkg_delete"
2121

2222
defaultfor 'os.name' => :openbsd
@@ -114,7 +114,7 @@ def install_options
114114
end
115115

116116
def uninstall_options
117-
[join_options(resource[:uninstall_options])]
117+
join_options(resource[:uninstall_options]) || []
118118
end
119119

120120
def uninstall

spec/unit/provider/package/openbsd_spec.rb

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
require 'stringio'
33

44
describe Puppet::Type.type(:package).provider(:openbsd) do
5+
include PuppetSpec::Fixtures
6+
57
let(:package) { Puppet::Type.type(:package).new(:name => 'bash', :provider => 'openbsd') }
68
let(:provider) { described_class.new(package) }
79

@@ -15,16 +17,17 @@
1517
before :each do
1618
# Stub some provider methods to avoid needing the actual software
1719
# 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")
1821
allow(described_class).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info')
1922
allow(described_class).to receive(:command).with(:pkgadd).and_return('/usr/sbin/pkg_add')
2023
allow(described_class).to receive(:command).with(:pkgdelete).and_return('/usr/sbin/pkg_delete')
21-
22-
allow(Puppet::FileSystem).to receive(:exist?)
2324
end
2425

2526
context "#instances" do
2627
it "should return nil if execution failed" do
28+
allow(described_class).to receive(:command).with(:pkginfo).and_return('/usr/sbin/pkg_info')
2729
expect(provider).to receive(:pkginfo).and_raise(Puppet::ExecutionFailure, 'wawawa')
30+
#expect(provider).to receive(:pkginfo).with(['-a', '-z'])
2831
expect(described_class.instances).to be_nil
2932
end
3033

@@ -43,10 +46,10 @@
4346

4447
it "should return all flavors if set" do
4548
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)
4750
instances = described_class.instances.map {|p| {:name => p.get(:name),
4851
:ensure => p.get(:ensure), :flavor => p.get(:flavor)}}
49-
expect(instances.size).to eq(2)
52+
expect(instances.size).to eq(5)
5053
expect(instances[0]).to eq({:name => 'autoconf%2.13', :ensure => 'present', :flavor => nil})
5154
expect(instances[1]).to eq({:name => 'autoconf%2.56', :ensure => 'present', :flavor => nil})
5255
expect(instances[2]).to eq({:name => 'bash', :ensure => 'present', :flavor => nil})
@@ -64,68 +67,43 @@
6467
end
6568

6669
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'
6972
provider.resource[:flavor] = 'static'
7073
expect(provider.get_full_name).to eq('bash--static')
7174
end
7275

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')
7779
end
7880

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--')
9784
end
98-
end
9985

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--')
10488
end
10589

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')
11094
end
11195

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
11796
end
11897

11998
context "#query" do
12099
it "should return the installed version if present" do
121100
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})
124103
end
125104

126105
it "should return nothing if not present" do
127106
provider.resource[:name] = 'zsh'
128-
expect(provider).to receive(:pkginfo).with('zsh').and_return('')
129107
expect(provider.query).to be_nil
130108
end
131109
end
@@ -152,8 +130,8 @@
152130
end
153131

154132
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([])
157135
end
158136

159137
it "should return uninstall_options when set" do
@@ -175,15 +153,15 @@
175153
context "#uninstall" do
176154
describe 'when uninstalling' do
177155
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--')
179157
provider.purge
180158
end
181159
end
182160

183161
describe 'with uninstall_options' do
184162
it 'should use uninstall_options as Array' do
185163
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--')
187165
provider.uninstall
188166
end
189167
end
@@ -198,9 +176,8 @@
198176
expect(provider.flavor).to eq('no_x11-python')
199177
end
200178

201-
it 'should remove and install the new flavor if different' do
179+
it 'should reinstall the new flavor if different' do
202180
provider.resource[:flavor] = 'no_x11-ruby'
203-
expect(provider).to receive(:uninstall).ordered
204181
expect(provider).to receive(:install).ordered
205182
provider.flavor = provider.resource[:flavor]
206183
end

0 commit comments

Comments
 (0)