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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#! /usr/bin/env ruby
require 'spec_helper'
provider_class = Puppet::Type.type(:package).provider(:zypper)
describe provider_class do
before(:each) do
# Create a mock resource
@resource = stub 'resource'
# A catch all; no parameters set
@resource.stubs(:[]).returns(nil)
# But set name and source
@resource.stubs(:[]).with(:name).returns "mypackage"
@resource.stubs(:[]).with(:ensure).returns :installed
@resource.stubs(:command).with(:zypper).returns "/usr/bin/zypper"
@provider = provider_class.new(@resource)
end
it "should have an install method" do
@provider = provider_class.new
@provider.should respond_to(:install)
end
it "should have an uninstall method" do
@provider = provider_class.new
@provider.should respond_to(:uninstall)
end
it "should have an update method" do
@provider = provider_class.new
@provider.should respond_to(:update)
end
it "should have a latest method" do
@provider = provider_class.new
@provider.should respond_to(:latest)
end
it "should have a install_options method" do
@provider = provider_class.new
@provider.should respond_to(:install_options)
end
describe "when installing with zypper version >= 1.0" do
it "should use a command-line with versioned package'" do
@resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "1.2.8"
@provider.expects(:zypper).with('--quiet', :install, '--auto-agree-with-licenses', '--no-confirm', 'mypackage-1.2.3-4.5.6')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
it "should use a command-line without versioned package" do
@resource.stubs(:should).with(:ensure).returns :latest
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "1.2.8"
@provider.expects(:zypper).with('--quiet', :install, '--auto-agree-with-licenses', '--no-confirm', '--name', 'mypackage')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
end
describe "when installing with zypper version = 0.6.104" do
it "should use a command-line with versioned package'" do
@resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "0.6.104"
@provider.expects(:zypper).with('--terse', :install, '--auto-agree-with-licenses', '--no-confirm', 'mypackage-1.2.3-4.5.6')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
it "should use a command-line without versioned package" do
@resource.stubs(:should).with(:ensure).returns :latest
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "0.6.104"
@provider.expects(:zypper).with('--terse', :install, '--auto-agree-with-licenses', '--no-confirm', '--name', 'mypackage')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
end
describe "when installing with zypper version = 0.6.13" do
it "should use a command-line with versioned package'" do
@resource.stubs(:should).with(:ensure).returns "1.2.3-4.5.6"
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "0.6.13"
@provider.expects(:zypper).with('--terse', :install, '--no-confirm', 'mypackage-1.2.3-4.5.6')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
it "should use a command-line without versioned package" do
@resource.stubs(:should).with(:ensure).returns :latest
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "0.6.13"
@provider.expects(:zypper).with('--terse', :install, '--no-confirm', '--name', 'mypackage')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
end
describe "when updating" do
it "should call install method of instance" do
@provider.expects(:install)
@provider.update
end
end
describe "when getting latest version" do
it "should return a version string with valid list-updates data from SLES11sp1" do
fake_data = File.read(my_fixture('zypper-list-updates-SLES11sp1.out'))
@resource.stubs(:[]).with(:name).returns "at"
@provider.expects(:zypper).with("list-updates").returns fake_data
@provider.latest.should == "3.1.8-1069.18.2"
end
end
it "should install a virtual package" do
@resource.stubs(:should).with(:ensure).returns :installed
@resource.stubs(:allow_virtual?).returns true
@provider.stubs(:zypper_version).returns "0.6.13"
@provider.expects(:zypper).with('--terse', :install, '--no-confirm', 'mypackage')
@provider.expects(:query).returns "mypackage 0 1.2.3 4.5.6 x86_64"
@provider.install
end
describe "when installing with zypper install options" do
it "should install the package without checking keys" do
@resource.stubs(:[]).with(:name).returns "php5"
@resource.stubs(:[]).with(:install_options).returns ['--no-gpg-check', {'-p' => '/vagrant/files/localrepo/'}]
@resource.stubs(:should).with(:ensure).returns "5.4.10-4.5.6"
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns "1.2.8"
@provider.expects(:zypper).with('--quiet', :install,
'--auto-agree-with-licenses', '--no-confirm', '--no-gpg-check', '-p=/vagrant/files/localrepo/', 'php5-5.4.10-4.5.6')
@provider.expects(:query).returns "php5 0 5.4.10 4.5.6 x86_64"
@provider.install
end
it "should install package with hash install options" do
@resource.stubs(:[]).with(:name).returns 'vim'
@resource.stubs(:[]).with(:install_options).returns([{ '--a' => 'foo', '--b' => '"quoted bar"' }])
@resource.stubs(:should).with(:ensure).returns :present
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns '1.2.8'
@provider.expects(:zypper).with('--quiet', :install, '--auto-agree-with-licenses', '--no-confirm', '--name', '--a=foo', '--b="quoted bar"', 'vim')
@provider.expects(:query).returns 'package vim is not installed'
@provider.install
end
it "should install package with array install options" do
@resource.stubs(:[]).with(:name).returns 'vim'
@resource.stubs(:[]).with(:install_options).returns([['--a', '--b', '--c']])
@resource.stubs(:should).with(:ensure).returns :present
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns '1.2.8'
@provider.expects(:zypper).with('--quiet', :install, '--auto-agree-with-licenses', '--no-confirm', '--name', '--a', '--b', '--c', 'vim')
@provider.expects(:query).returns 'package vim is not installed'
@provider.install
end
it "should install package with string install options" do
@resource.stubs(:[]).with(:name).returns 'vim'
@resource.stubs(:[]).with(:install_options).returns(['--a --b --c'])
@resource.stubs(:should).with(:ensure).returns :present
@resource.stubs(:allow_virtual?).returns false
@provider.stubs(:zypper_version).returns '1.2.8'
@provider.expects(:zypper).with('--quiet', :install, '--auto-agree-with-licenses', '--no-confirm', '--name', '--a --b --c', 'vim')
@provider.expects(:query).returns 'package vim is not installed'
@provider.install
end
end
end
|