forked from puppetlabs/puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxbps_spec.rb
143 lines (117 loc) · 5.15 KB
/
xbps_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
require "spec_helper"
require "stringio"
describe Puppet::Type.type(:package).provider(:xbps) do
before do
@resource = Puppet::Type.type(:package).new(name: "gcc", provider: "xbps")
@provider = described_class.new(@resource)
@resolver = Puppet::Util
allow(described_class).to receive(:which).with("/usr/bin/xbps-install").and_return("/usr/bin/xbps-install")
allow(described_class).to receive(:which).with("/usr/bin/xbps-remove").and_return("/usr/bin/xbps-remove")
allow(described_class).to receive(:which).with("/usr/bin/xbps-query").and_return("/usr/bin/xbps-query")
end
it { is_expected.to be_installable }
it { is_expected.to be_uninstallable }
it { is_expected.to be_install_options }
it { is_expected.to be_uninstall_options }
it { is_expected.to be_upgradeable }
it { is_expected.to be_holdable }
it { is_expected.to be_virtual_packages }
it "should be the default provider on 'os.name' => Void" do
expect(Facter).to receive(:value).with('os.name').and_return("Void")
expect(described_class.default?).to be_truthy
end
describe "when determining instances" do
it "should return installed packages" do
sample_installed_packages = %{
ii gcc-12.2.0_1 GNU Compiler Collection
ii ruby-devel-3.1.3_1 Ruby programming language - development files
}
expect(described_class).to receive(:execpipe).with(["/usr/bin/xbps-query", "-l"])
.and_yield(StringIO.new(sample_installed_packages))
instances = described_class.instances
expect(instances.length).to eq(2)
expect(instances[0].properties).to eq({
:name => "gcc",
:ensure => "12.2.0_1",
:provider => :xbps,
})
expect(instances[1].properties).to eq({
:name => "ruby-devel",
:ensure => "3.1.3_1",
:provider => :xbps,
})
end
it "should warn on invalid input" do
expect(described_class).to receive(:execpipe).and_yield(StringIO.new("blah"))
expect(described_class).to receive(:warning).with('Failed to match line \'blah\'')
expect(described_class.instances).to eq([])
end
end
describe "when installing" do
it "and install_options are given it should call xbps to install the package quietly with the passed options" do
@resource[:install_options] = ["-x", { "--arg" => "value" }]
args = ["-S", "-y", "-x", "--arg=value", @resource[:name]]
expect(@provider).to receive(:xbps_install).with(*args).and_return("")
expect(described_class).to receive(:execpipe).with(["/usr/bin/xbps-query", "-l"])
@provider.install
end
it "and source is given it should call xbps to install the package from the source as repository" do
@resource[:source] = "/path/to/xbps/containing/directory"
args = ["-S", "-y", "--repository=#{@resource[:source]}", @resource[:name]]
expect(@provider).to receive(:xbps_install).at_least(:once).with(*args).and_return("")
expect(described_class).to receive(:execpipe).with(["/usr/bin/xbps-query", "-l"])
@provider.install
end
end
describe "when updating" do
it "should call install" do
expect(@provider).to receive(:install).and_return("ran install")
expect(@provider.update).to eq("ran install")
end
end
describe "when uninstalling" do
it "should call xbps to remove the right package quietly" do
args = ["-R", "-y", @resource[:name]]
expect(@provider).to receive(:xbps_remove).with(*args).and_return("")
@provider.uninstall
end
it "adds any uninstall_options" do
@resource[:uninstall_options] = ["-x", { "--arg" => "value" }]
args = ["-R", "-y", "-x", "--arg=value", @resource[:name]]
expect(@provider).to receive(:xbps_remove).with(*args).and_return("")
@provider.uninstall
end
end
describe "when determining the latest version" do
it "should return the latest version number of the package" do
@resource[:name] = "ruby-devel"
expect(described_class).to receive(:execpipe).with(["/usr/bin/xbps-query", "-l"]).and_yield(StringIO.new(%{
ii ruby-devel-3.1.3_1 Ruby programming language - development files
}))
expect(@provider.latest).to eq("3.1.3_1")
end
end
describe "when querying" do
it "should call self.instances and return nil if the package is missing" do
expect(described_class).to receive(:instances)
.and_return([])
expect(@provider.query).to be_nil
end
it "should get real-package in case allow_virtual is true" do
@resource[:name] = "nodejs-runtime"
@resource[:allow_virtual] = true
expect(described_class).to receive(:execpipe).with(["/usr/bin/xbps-query", "-l"])
.and_yield(StringIO.new(""))
args = ["-Rs", @resource[:name]]
expect(@provider).to receive(:xbps_query).with(*args).and_return(%{
[*] nodejs-16.19.0_1 Evented I/O for V8 javascript
[-] nodejs-lts-12.22.10_2 Evented I/O for V8 javascript'
})
expect(@provider.query).to eq({
:name => "nodejs",
:ensure => "16.19.0_1",
:provider => :xbps,
})
end
end
end