-
Notifications
You must be signed in to change notification settings - Fork 8
/
yast_spec.rb
305 lines (227 loc) · 10.6 KB
/
yast_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
require 'spec_helper'
describe SUSE::Connect::YaST do
subject { SUSE::Connect::YaST }
describe '#announce_system' do
let(:params) { [{}, 'sles12-x86_64'] }
before { Client.any_instance.stub :announce_system }
it 'calls announce_system on an instance of Client' do
Client.any_instance.should_receive(:announce_system)
subject.announce_system({}, nil)
end
it 'passes distro_target parameter to announce' do
Client.any_instance.should_receive(:announce_system).with(params.last)
subject.announce_system(*params)
end
it 'forwards all params to an instance of Client' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:announce_system)
subject.announce_system(*params)
end
it 'falls back to use an empty Hash as params if none are specified' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:announce_system)
subject.announce_system
end
end
describe '#update_system' do
before { Client.any_instance.stub :update_system }
it 'calls update_system on an instance of Client' do
Client.any_instance.should_receive(:update_system)
subject.update_system
end
it 'forwards distro_target parameter to client' do
Client.any_instance.should_receive(:update_system).with('my-distro-target')
subject.update_system({}, 'my-distro-target')
end
it 'uses client params' do
expect_any_instance_of(SUSE::Connect::Config)
subject.update_system(:language => 'de')
end
end
describe '#activate_product' do
let(:client_params) { { token: 'regcode' } }
let(:product) { Remote::Product.new(identifier: 'win95') }
let(:email) { 'foo@bar.zer' }
before { Client.any_instance.stub :activate_product }
it 'calls activate_product on an instance of Client' do
Client.any_instance.should_receive(:activate_product)
subject.activate_product(nil)
end
it 'forwards all params to an instance of Client' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
expect_any_instance_of(SUSE::Connect::Config).to receive(:merge!).with(client_params).and_call_original
Client.any_instance.should_receive(:activate_product)
subject.activate_product(*[product, client_params, email])
end
it 'falls back to use an empty Hash as params if none are specified' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:activate_product)
subject.activate_product(nil)
end
it 'uses product_ident and email as parameter for Client#activate_product' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:activate_product).with(product, email)
subject.activate_product(*[product, client_params, email])
end
end
describe '#upgrade_product' do
let(:product) { Remote::Product.new(identifier: 'win98') }
let(:client_params) { { :foo => 'oink' } }
before { Client.any_instance.stub :upgrade_product }
it 'calls upgrade_product on an instance of Client' do
Client.any_instance.should_receive :upgrade_product
subject.upgrade_product(product)
end
it 'forwards all params to an instance of Client' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
expect_any_instance_of(SUSE::Connect::Config).to receive(:merge!).with(client_params).and_call_original
subject.upgrade_product product, client_params
end
it 'falls back to use an empty Hash as params if none are specified' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
subject.upgrade_product product
end
it 'forwards product_ident to Client#upgrade_product' do
Client.any_instance.should_receive(:upgrade_product).with(product)
subject.upgrade_product product
end
end
describe '#show_product' do
let(:product) { Remote::Product.new(identifier: 'tango') }
let(:client_params) { { :foo => 'oink' } }
before { Client.any_instance.stub :show_product }
it 'calls list_products on an instance of Client' do
Client.any_instance.should_receive(:show_product)
subject.show_product product
end
it 'forwards all params to an instance of Client' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:show_product)
subject.show_product product, client_params
end
it 'falls back to use an empty Hash as params if none are specified' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:show_product)
subject.show_product product
end
it 'uses product as parameter for Client#list_products' do
Client.should_receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
Client.any_instance.should_receive(:show_product).with(product)
subject.show_product product
end
end
describe '#product_activated?' do
let(:product) { Remote::Product.new(identifier: 'tango') }
it 'returns false if no credentials' do
expect(System).to receive(:credentials?).and_return(false)
expect(subject.product_activated?(product)).to be false
end
it 'checks if the given product is already activated in SCC' do
expect(System).to receive(:credentials?).and_return(true)
expect_any_instance_of(Status).to receive(:activated_products).and_return([product])
expect(subject.product_activated?(product)).to be true
end
it 'allows to pass a Hash with params to instantiate the client' do
allow(System).to receive(:credentials?).and_return(true)
status = double 'status'
params_hash = { foo: 'bar' }
allow(status).to receive(:activated_products).and_return([product])
expect(subject).to receive(:status).with(params_hash).and_return status
expect(subject.product_activated?(product, params_hash)).to be true
end
end
describe '#system_migrations' do
let(:products) do
[
Remote::Product.new(:identifier => 'SLES', :version => '12', :arch => 'x86_64', :release_type => 'HP-CNB'),
Remote::Product.new(:identifier => 'SUSE-Cloud', :version => '7', :arch => 'x86_64', :release_type => nil)
]
end
let(:client_params) { { :foo => 'oink' } }
it 'calls system_migrations on an instance of Client' do
expect(Client).to receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
expect_any_instance_of(Client).to receive(:system_migrations)
subject.system_migrations products, client_params
end
it 'uses products list as parameter for Client#system_migrations' do
expect(Client).to receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
expect_any_instance_of(Client).to receive(:system_migrations).with(products)
subject.system_migrations products, client_params
end
it 'returns the output received from Client' do
expected_migration = [[Remote::Product.new(identifier: 'SLES')]]
expect(Client).to receive(:new).with(instance_of(SUSE::Connect::Config)).and_call_original
expect_any_instance_of(Client).to receive(:system_migrations).with(products).and_return(expected_migration)
actual_migration = subject.system_migrations products, client_params
expect(actual_migration).to eq(expected_migration)
end
end
describe '#all_products' do
let(:zypper_product) { Zypper::Product.new(:name => 'SLES', :version => '12', :arch => 'x86_64') }
let(:remote_product) { Remote::Product.new(:identifier => 'SLES', :version => '12', :arch => 'x86_64', :release_type => 'HP-CNB') }
it 'forwards to status installed products and status activated products' do
expect_any_instance_of(Status).to receive(:installed_products).and_return([zypper_product])
expect_any_instance_of(Status).to receive(:activated_products).and_return([remote_product])
result = SUSE::Connect::YaST.all_products
expect(result).to match_array([Product.transform(zypper_product), Product.transform(remote_product)])
end
end
describe '#add_service' do
it 'forwards to zypper add_service' do
service_url = 'http://bla.bla'
service_name = 'bla'
expect(SUSE::Connect::Zypper).to receive(:add_service).with(service_url, service_name)
SUSE::Connect::YaST.add_service(service_url, service_name)
end
end
describe '#remove_service' do
it 'forwards to zypper remove_service' do
service_name = 'bla'
expect(SUSE::Connect::Zypper).to receive(:remove_service).with(service_name)
SUSE::Connect::YaST.remove_service(service_name)
end
end
describe '#write_config' do
let(:params) { { url: 'http://scc.foo.com' } }
it 'merges passed params into config' do
params = { url: 'http://smt.local.domain' }
allow_any_instance_of(SUSE::Connect::Config).to receive(:write!).and_return true
expect_any_instance_of(SUSE::Connect::Config).to receive(:merge!).with(params).and_call_original
subject.write_config(params)
end
it 'calls write_config on an instance of config' do
expect_any_instance_of(SUSE::Connect::Config).to receive(:write!)
subject.write_config
end
end
describe '#import_certificate' do
it 'calls import certificate method from SSLCertificate class' do
expect(SSLCertificate).to receive(:import).with(:foo)
subject.import_certificate(:foo)
end
end
describe '#cert_sha1_fingerprint' do
it 'calls cert_sha1_fingerprint method from SSLCertificate class' do
expect(SSLCertificate).to receive(:sha1_fingerprint).with(:foo)
subject.cert_sha1_fingerprint(:foo)
end
end
describe '#cert_sha256_fingerprint' do
it 'calls cert_sha256_fingerprint method from SSLCertificate class' do
expect(SSLCertificate).to receive(:sha256_fingerprint).with(:foo)
subject.cert_sha256_fingerprint(:foo)
end
end
describe '#status' do
it 'merges passed parameters with config' do
params = { insecure: true }
expect_any_instance_of(SUSE::Connect::Config).to receive(:merge!).with(params)
allow(Status).to receive(:new)
subject.status(params)
end
it 'assigns new client to status with passed hash' do
expect(Status).to receive(:new).with(instance_of(SUSE::Connect::Config))
subject.status(:foo => :bar)
end
end
end