2
2
require 'spec_helper'
5
5
provider = Puppet::Type.type(:package).provider(:pacman)
8
let(:no_extra_options) { { :custom_environment => {} } }
9
let(:executor) { Puppet::Util::Execution }
10
let(:resolver) { Puppet::Util }
9
provider.stubs(:command).with(:pacman).returns('/usr/bin/pacman')
10
@resource = stub 'resource'
11
@resource.stubs(:[]).returns("package")
12
@resource.stubs(:name).returns("name")
13
resolver.stubs(:which).with('/usr/bin/pacman').returns('/usr/bin/pacman')
14
provider.stubs(:which).with('/usr/bin/pacman').returns('/usr/bin/pacman')
15
@resource = Puppet::Type.type(:package).new(:name => 'package')
13
16
@provider = provider.new(@resource)
23
it "should call pacman" do
26
it "should call pacman to install the right package quietly" do
28
args[0] == "/usr/bin/pacman"
30
with(["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-Sy", @resource[:name]], no_extra_options).
35
it "should be quiet" do
39
args[1,2] == ["--noconfirm", "--noprogressbar"]
46
it "should install the right package" do
50
args[3,4] == ["-Sy", @resource[0]]
57
36
it "should raise an ExecutionFailure if the installation failed" do
58
provider.stubs(:execute).returns("")
37
executor.stubs(:execute).returns("")
59
38
@provider.expects(:query).returns(nil)
61
40
lambda { @provider.install }.should raise_exception(Puppet::ExecutionFailure)
43
context "when :source is specified" do
45
@install = sequence("install")
48
context "recognizable by pacman" do
51
http://some.package.in/the/air
52
ftp://some.package.in/the/air
54
it "should install #{source} directly" do
55
@resource[:source] = source
57
executor.expects(:execute).
58
with(all_of(includes("-Sy"), includes("--noprogressbar")), no_extra_options).
59
in_sequence(@install).
62
executor.expects(:execute).
63
with(all_of(includes("-U"), includes(source)), no_extra_options).
64
in_sequence(@install).
72
context "as a file:// URL" do
74
@package_file = "file:///some/package/file"
75
@actual_file_path = "/some/package/file"
76
@resource[:source] = @package_file
79
it "should install from the path segment of the URL" do
80
executor.expects(:execute).
81
with(all_of(includes("-Sy"),
82
includes("--noprogressbar"),
83
includes("--noconfirm")),
85
in_sequence(@install).
88
executor.expects(:execute).
89
with(all_of(includes("-U"), includes(@actual_file_path)), no_extra_options).
90
in_sequence(@install).
97
context "as a puppet URL" do
99
@resource[:source] = "puppet://server/whatever"
103
lambda { @provider.install }.should raise_error(Puppet::Error)
107
context "as a malformed URL" do
109
@resource[:source] = "blah://"
113
lambda { @provider.install }.should raise_error(Puppet::Error)
65
119
describe "when updating" do
72
126
describe "when uninstalling" do
73
it "should call pacman" do
127
it "should call pacman to remove the right package quietly" do
75
129
expects(:execute).
77
args[0] == "/usr/bin/pacman"
130
with(["/usr/bin/pacman", "--noconfirm", "--noprogressbar", "-R", @resource[:name]], no_extra_options).
81
133
@provider.uninstall
84
it "should be quiet" do
88
args[1,2] == ["--noconfirm", "--noprogressbar"]
95
it "should remove the right package" do
99
args[3,4] == ["-R", @resource[0]]
107
137
describe "when querying" do
108
138
it "should query pacman" do
110
140
expects(:execute).
111
with(["/usr/bin/pacman", "-Qi", @resource[0]])
141
with(["/usr/bin/pacman", "-Qi", @resource[:name]], no_extra_options)
136
166
Description : A library-based package manager with dependency support
139
provider.expects(:execute).returns(query_output)
169
executor.expects(:execute).returns(query_output)
140
170
@provider.query.should == {:ensure => "1.01.3-2"}
143
173
it "should return a nil if the package isn't found" do
144
provider.expects(:execute).returns("")
174
executor.expects(:execute).returns("")
145
175
@provider.query.should be_nil
148
178
it "should return a hash indicating that the package is missing on error" do
149
provider.expects(:execute).raises(Puppet::ExecutionFailure.new("ERROR!"))
179
executor.expects(:execute).raises(Puppet::ExecutionFailure.new("ERROR!"))
150
180
@provider.query.should == {
151
181
:ensure => :purged,
152
182
:status => 'missing',
153
:name => @resource[0],
183
:name => @resource[:name],
196
226
describe "when determining the latest version" do
197
227
it "should refresh package list" do
198
refreshed = states('refreshed').starts_as('unrefreshed')
228
get_latest_version = sequence("get_latest_version")
200
230
expects(:execute).
201
when(refreshed.is('unrefreshed')).
202
with(['/usr/bin/pacman', '-Sy']).
203
then(refreshed.is('refreshed'))
231
in_sequence(get_latest_version).
232
with(['/usr/bin/pacman', '-Sy'], no_extra_options)
207
when(refreshed.is('refreshed')).
236
in_sequence(get_latest_version).
213
242
it "should get query pacman for the latest version" do
214
refreshed = states('refreshed').starts_as('unrefreshed')
243
get_latest_version = sequence("get_latest_version")
217
when(refreshed.is('unrefreshed')).
218
then(refreshed.is('refreshed'))
246
in_sequence(get_latest_version)
221
249
expects(:execute).
222
when(refreshed.is('refreshed')).
223
with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[0]]).
250
in_sequence(get_latest_version).
251
with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[:name]], no_extra_options).
229
257
it "should return the version number from pacman" do
231
259
expects(:execute).
233
261
returns("1.00.2-3\n")