@@ -182,3 +182,205 @@ func TestPath(t *testing.T) {
182
182
IsSecret : false ,
183
183
}, cfg .Get (ProxyCAFile ))
184
184
}
185
+
186
+ func TestWhenInvalidKeySetThenErrorIsThrown (t * testing.T ) {
187
+ // Given
188
+ cfg , err := newInMemoryConfig ()
189
+ require .NoError (t , err )
190
+
191
+ // When + Then
192
+ _ , err = cfg .Set ("i-dont-exist" , "i-should-not-be-set" )
193
+ assert .Error (t , err , "Configuration property 'i-dont-exist' does not exist" )
194
+ }
195
+
196
+ func TestSetDeveloperPasswordIsSetInConfig (t * testing.T ) {
197
+ // Given
198
+ cfg , err := newInMemoryConfig ()
199
+ require .NoError (t , err )
200
+
201
+ // When
202
+ _ , err = cfg .Set (DeveloperPassword , "secret-developer-password" )
203
+ require .NoError (t , err )
204
+
205
+ // Then
206
+ assert .Equal (t , SettingValue {
207
+ Value : "secret-developer-password" ,
208
+ Invalid : false ,
209
+ }, cfg .Get (DeveloperPassword ))
210
+ }
211
+
212
+ var configDefaultValuesTestArguments = []struct {
213
+ key string
214
+ defaultValue interface {}
215
+ }{
216
+ {
217
+ KubeAdminPassword , "" ,
218
+ },
219
+ {
220
+ DeveloperPassword , "developer" ,
221
+ },
222
+ {
223
+ CPUs , uint (4 ),
224
+ },
225
+ {
226
+ Memory , uint (10752 ),
227
+ },
228
+ {
229
+ DiskSize , 31 ,
230
+ },
231
+ {
232
+ NameServer , "" ,
233
+ },
234
+ {
235
+ PullSecretFile , "" ,
236
+ },
237
+ {
238
+ DisableUpdateCheck , false ,
239
+ },
240
+ {
241
+ ExperimentalFeatures , false ,
242
+ },
243
+ {
244
+ EmergencyLogin , false ,
245
+ },
246
+ {
247
+ PersistentVolumeSize , 15 ,
248
+ },
249
+ {
250
+ HostNetworkAccess , false ,
251
+ },
252
+ {
253
+ HTTPProxy , "" ,
254
+ },
255
+ {
256
+ HTTPSProxy , "" ,
257
+ },
258
+ {
259
+ NoProxy , "" ,
260
+ },
261
+ {
262
+ ProxyCAFile , Path ("" ),
263
+ },
264
+ {
265
+ EnableClusterMonitoring , false ,
266
+ },
267
+ {
268
+ ConsentTelemetry , "" ,
269
+ },
270
+ {
271
+ IngressHTTPPort , 80 ,
272
+ },
273
+ {
274
+ IngressHTTPSPort , 443 ,
275
+ },
276
+ {
277
+ EnableBundleQuayFallback , false ,
278
+ },
279
+ {
280
+ Preset , "openshift" ,
281
+ },
282
+ }
283
+
284
+ func TestDefaultKeyValuesSetInConfig (t * testing.T ) {
285
+ for _ , tt := range configDefaultValuesTestArguments {
286
+ t .Run (tt .key , func (t * testing.T ) {
287
+ // Given
288
+ cfg , err := newInMemoryConfig ()
289
+ require .NoError (t , err )
290
+
291
+ // When + Then
292
+ assert .Equal (t , SettingValue {
293
+ Value : tt .defaultValue ,
294
+ Invalid : false ,
295
+ IsDefault : true ,
296
+ }, cfg .Get (tt .key ))
297
+ })
298
+ }
299
+ }
300
+
301
+ var configProvidedValuesTestArguments = []struct {
302
+ key string
303
+ providedValue interface {}
304
+ }{
305
+ {
306
+ KubeAdminPassword , "kubeadmin-secret-password" ,
307
+ },
308
+ {
309
+ DeveloperPassword , "developer-secret-password" ,
310
+ },
311
+ {
312
+ CPUs , uint (8 ),
313
+ },
314
+ {
315
+ Memory , uint (21504 ),
316
+ },
317
+ {
318
+ DiskSize , 62 ,
319
+ },
320
+ {
321
+ NameServer , "127.0.0.1" ,
322
+ },
323
+ {
324
+ DisableUpdateCheck , true ,
325
+ },
326
+ {
327
+ ExperimentalFeatures , true ,
328
+ },
329
+ {
330
+ EmergencyLogin , true ,
331
+ },
332
+ {
333
+ PersistentVolumeSize , 20 ,
334
+ },
335
+ {
336
+ HTTPProxy , "http://proxy-via-http-proxy-property:3128" ,
337
+ },
338
+ {
339
+ HTTPSProxy , "https://proxy-via-http-proxy-property:3128" ,
340
+ },
341
+ {
342
+ NoProxy , "http://no-proxy-property:3128" ,
343
+ },
344
+ {
345
+ EnableClusterMonitoring , true ,
346
+ },
347
+ {
348
+ ConsentTelemetry , "yes" ,
349
+ },
350
+ {
351
+ IngressHTTPPort , 8080 ,
352
+ },
353
+ {
354
+ IngressHTTPSPort , 6443 ,
355
+ },
356
+ {
357
+ EnableBundleQuayFallback , true ,
358
+ },
359
+ {
360
+ Preset , "microshift" ,
361
+ },
362
+ }
363
+
364
+ func TestSetProvidedValuesOverrideDefaultValuesInConfig (t * testing.T ) {
365
+ for _ , tt := range configProvidedValuesTestArguments {
366
+ t .Run (tt .key , func (t * testing.T ) {
367
+
368
+ // When + Then
369
+
370
+ // Given
371
+ cfg , err := newInMemoryConfig ()
372
+ require .NoError (t , err )
373
+
374
+ // When
375
+ _ , err = cfg .Set (tt .key , tt .providedValue )
376
+ require .NoError (t , err )
377
+
378
+ // Then
379
+ assert .Equal (t , SettingValue {
380
+ Value : tt .providedValue ,
381
+ Invalid : false ,
382
+ IsDefault : false ,
383
+ }, cfg .Get (tt .key ))
384
+ })
385
+ }
386
+ }
0 commit comments