/
addon_spec.rb
337 lines (268 loc) · 9.96 KB
/
addon_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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
#! /usr/bin/env rspec
require_relative "spec_helper"
require "yaml"
describe Registration::Addon do
before(:each) do
addon_reset_cache
end
subject(:addon) do
Registration::Addon.new(addon_generator)
end
describe ".find_all" do
it "find all addons for current base product" do
prod1 = addon_generator
prod2 = addon_generator
registration = double(
activated_products: [],
get_addon_list: [prod1, prod2]
)
expect(Registration::Addon.find_all(registration).size).to be 2
end
it "find even dependend products" do
prod1 = addon_with_child_generator
registration = double(
activated_products: [],
get_addon_list: [prod1]
)
expect(Registration::Addon.find_all(registration).size).to be 2
end
it "sets properly dependencies between addons" do
prod1 = addon_with_child_generator
registration = double(
activated_products: [],
get_addon_list: [prod1]
)
addons = Registration::Addon.find_all(registration)
expect(addons.any? { |addon| addon.children.size == 1 }).to eq(true)
expect(addons.any?(&:depends_on)).to eq(true)
end
it "sets the registration status from status call" do
prod1 = addon_generator("name" => "prod1")
prod2 = addon_generator("name" => "prod2")
registration = double(
activated_products: [prod1],
get_addon_list: [prod1, prod2]
)
addons = Registration::Addon.find_all(registration)
addon1 = addons.find { |addon| addon.name == "prod1" }
addon2 = addons.find { |addon| addon.name == "prod2" }
expect(addon1.registered?).to eq(true)
expect(addon2.registered?).to eq(false)
end
it "sets the registration status for dependent addons" do
registration = double(
activated_products: load_yaml_fixture("activated_products.yml"),
get_addon_list: load_yaml_fixture("pure_addons.yml")
)
addons = Registration::Addon.find_all(registration)
ha = addons.find { |addon| addon.identifier == "sle-ha" }
ha_geo = ha.children.first
expect(ha.registered?).to eq(true)
expect(ha_geo.registered?).to eq(true)
end
end
describe ".selected" do
it "returns array with selected addons" do
expect(Registration::Addon.selected).to be_a(Array)
end
end
describe ".registered" do
it "returns array of already registered addons" do
expect(Registration::Addon.registered).to be_a(Array)
end
end
describe ".registered_not_installed" do
it "returns an array of already registered addons but not installed" do
prod1 = addon_generator("name" => "prod1")
prod2 = addon_generator("name" => "prod2")
registration = double(
activated_products: [prod2],
get_addon_list: [prod1, prod2]
)
addons = Registration::Addon.find_all(registration)
addon2 = addons.find { |addon| addon.name == "prod2" }
expect(Registration::SwMgmt).to receive(:installed_products).and_return([])
expect(Yast::Pkg).to receive(:ResolvableProperties).with(prod2.identifier, :product, "")
.and_return(["status" => :available])
reg_not_installed_addons = Registration::Addon.registered_not_installed
expect(reg_not_installed_addons.size).to eql(1)
expect(reg_not_installed_addons.first.name).to eql(addon2.name)
end
it "does not return addons without available products" do
prod = addon_generator("name" => "prod")
registration = double(
activated_products: [prod],
get_addon_list: [prod]
)
Registration::Addon.find_all(registration)
expect(Registration::SwMgmt).to receive(:installed_products).and_return([])
expect(Yast::Pkg).to receive(:ResolvableProperties).with(prod.identifier, :product, "")
.and_return([])
expect(Registration::Addon.registered_not_installed).to be_empty
end
end
describe "#unregistered" do
it "marks addon as unregistered" do
Registration::Addon.registered << addon
addon.unregistered
expect(Registration::Addon.registered).to_not include(addon)
end
it "do nothing if addon is not registered" do
expect(Registration::Addon.registered).to_not include(addon)
expect { addon.unregistered }.to_not raise_error
end
end
describe "#selected?" do
it "returns if addon is selected for installation" do
expect(addon.selected?).to eq(false)
Registration::Addon.selected << addon
expect(addon.selected?).to eq(true)
end
end
describe "#selected" do
it "marks addon as selected" do
expect(Registration::Addon.selected.include?(addon)).to eq(false)
addon.selected
expect(Registration::Addon.selected.include?(addon)).to eq(true)
end
it "adds to list of selected only one" do
addon.selected
addon.selected
expect(Registration::Addon.selected.count(addon)).to be 1
end
end
describe "#unselected" do
it "marks addon as unselected" do
Registration::Addon.selected << addon
addon.unselected
expect(Registration::Addon.selected.include?(addon)).to eq(false)
end
it "do nothing if addon is not selected" do
expect { addon.unselected }.to_not raise_error
end
end
describe "#toggle_selected" do
it "marks an unselected addon as selected" do
expect(Registration::Addon.selected.include?(addon)).to eq(false)
addon.toggle_selected
expect(Registration::Addon.selected.include?(addon)).to eq(true)
end
it "marks a selected addon as unselected" do
Registration::Addon.selected << addon
expect(Registration::Addon.selected.include?(addon)).to eq(true)
addon.toggle_selected
expect(Registration::Addon.selected.include?(addon)).to eq(false)
end
end
describe "#registered?" do
it "returns if addon is already registered" do
expect(addon.registered?).to eq(false)
Registration::Addon.registered << addon
expect(addon.registered?).to eq(true)
end
end
describe "#beta_release?" do
it "returns true if addon is beta release" do
product = addon_generator("release_stage" => "beta")
addon = Registration::Addon.new(product)
expect(addon.beta_release?).to eq(true)
end
it "returns false if addon is not beta release" do
product = addon_generator("release_stage" => "production")
addon = Registration::Addon.new(product)
expect(addon.beta_release?).to eq(false)
end
end
describe "#label" do
it "returns short name when the long name is nil" do
product = addon_generator
product.friendly_name = nil
addon = Registration::Addon.new(product)
expect(addon.label).to eq(addon.name)
end
it "returns short name when the long name is empty" do
product = addon_generator("friendly_name" => "")
addon = Registration::Addon.new(product)
expect(addon.label).to eq(addon.name)
end
it "returns long name if it is present" do
expect(addon.label).to eq(addon.friendly_name)
end
end
describe "#selectable?" do
let(:addons) do
Registration::Addon.find_all(
double(
get_addon_list: [addon_with_child_generator],
activated_products: []
)
)
end
let(:parent) { addons.first }
let(:child) { parent.children.first }
it "returns false when the addon has been already registered" do
addon.registered
expect(addon.selectable?).to eq(false)
end
it "returns true when the addon has not been already registered" do
expect(addon.selectable?).to eq(true)
end
it "returns false when the parent is not selected or registered" do
expect(child.selectable?).to eq(false)
end
it "returns true when the parent is selected" do
parent.selected
expect(child.selectable?).to eq(true)
end
it "returns true when the parent is registered" do
parent.registered
expect(child.selectable?).to eq(true)
end
it "returns false when any child is selected" do
child.selected
expect(parent.selectable?).to eq(false)
end
it "returns false when the addon is not available" do
product = addon_generator("available" => false)
addon = Registration::Addon.new(product)
expect(addon.selectable?).to eq(false)
end
it "returns true when the addon is available" do
product = addon_generator("available" => true)
addon = Registration::Addon.new(product)
expect(addon.selectable?).to eq(true)
end
it "returns true when the addon availability is not set" do
expect(addon.selectable?).to eq(true)
end
end
describe "#updates_addon?" do
it "returns true if the old addon has the same name" do
product = addon_generator("zypper_name" => "sle-sdk")
new_addon = Registration::Addon.new(product)
old_addon = { "name" => "sle-sdk", "version" => "12", "arch" => "x86_64" }
expect(new_addon.updates_addon?(old_addon)).to eq(true)
end
it "returns true if the old addon is a predecessor" do
# "sle-haegeo" (SLE11-SP2) has been renamed to "sle-ha-geo" (SLE12)
product = addon_generator("zypper_name" => "sle-ha-geo",
"former_identifier" => "sle-haegeo")
new_addon = Registration::Addon.new(product)
old_addon = { "name" => "sle-haegeo", "version" => "12", "arch" => "x86_64" }
expect(new_addon.updates_addon?(old_addon)).to eq(true)
end
it "returns false if the old addon is different" do
product = addon_generator("zypper_name" => "sle-sdk")
new_addon = Registration::Addon.new(product)
old_addon = { "name" => "sle-hae", "version" => "12", "arch" => "x86_64" }
expect(new_addon.updates_addon?(old_addon)).to eq(false)
end
end
describe "#to_h" do
it "returns a Hash representation" do
product = addon_generator
addon = Registration::Addon.new(product)
expect(addon.to_h).to be_a(Hash)
end
end
end