@@ -250,8 +250,24 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
250
250
}
251
251
252
252
harness .UpdateAccount (newAccountName )
253
+ harness .mariaDBHelper .SimulateMariaDBAccountCompleted (newAccountName )
253
254
254
- harness .runAccountUpdateWithWait (oldAccountName , newAccountName )
255
+ mariaDBHelper .Logger .Info (
256
+ fmt .Sprintf ("Service should move to run fully off MariaDBAccount %s and remove finalizer from %s" ,
257
+ newAccountName , oldAccountName ),
258
+ )
259
+
260
+ // finalizer is attached to new account
261
+ Eventually (func () []string {
262
+ newMariadbAccount := mariaDBHelper .GetMariaDBAccount (newAccountName )
263
+ return newMariadbAccount .Finalizers
264
+ }, timeout , interval ).Should (ContainElement (harness .finalizerName ))
265
+
266
+ // finalizer removed from old account
267
+ Eventually (func () []string {
268
+ oldMariadbAccount := mariaDBHelper .GetMariaDBAccount (oldAccountName )
269
+ return oldMariadbAccount .Finalizers
270
+ }, timeout , interval ).ShouldNot (ContainElement (harness .finalizerName ))
255
271
256
272
// CreateOrPatchDBByName will add a label referring to the database
257
273
Eventually (func () string {
@@ -322,33 +338,36 @@ func (harness *MariaDBTestHarness) RunBasicSuite() {
322
338
}
323
339
324
340
// RunURLAssertSuite asserts that a database URL is set up with the correct
325
- // username and password, and that this is updated when the account changes
341
+ // username and password, and that this is updated when the account changes.
342
+ // account change is detected via finalizer
326
343
func (harness * MariaDBTestHarness ) RunURLAssertSuite (assertURL assertsURL ) {
327
344
When (fmt .Sprintf ("The %s service is fully running" , harness .description ), func () {
328
345
BeforeEach (func () {
329
346
harness .init ()
330
347
})
331
348
332
349
BeforeEach (func () {
333
- mariaDBHelper , timeout , interval := harness .mariaDBHelper , harness . timeout , harness . interval
350
+ mariaDBHelper := harness .mariaDBHelper
334
351
335
352
oldAccountName := types.NamespacedName {
336
353
Name : "some-old-account" ,
337
354
Namespace : harness .namespace ,
338
355
}
339
356
357
+ k8sClient := mariaDBHelper .K8sClient
358
+
359
+ // create MariaDBAccount / secret ahead of time, to suit controllers
360
+ // that dont directly do EnsureMariaDBAccount
361
+ mariadbAccount , mariadbSecret := mariaDBHelper .CreateMariaDBAccountAndSecret (oldAccountName , mariadbv1.MariaDBAccountSpec {})
362
+ DeferCleanup (k8sClient .Delete , mariaDBHelper .Ctx , mariadbSecret )
363
+ DeferCleanup (k8sClient .Delete , mariaDBHelper .Ctx , mariadbAccount )
364
+
340
365
// create the CR with old account
341
366
harness .SetupCR (oldAccountName )
342
367
343
368
// also simulate that it got completed
344
369
mariaDBHelper .SimulateMariaDBAccountCompleted (oldAccountName )
345
370
346
- // wait for finalizer to be set on the account
347
- Eventually (func () []string {
348
- oldMariadbAccount := mariaDBHelper .GetMariaDBAccount (oldAccountName )
349
- return oldMariadbAccount .Finalizers
350
- }, timeout , interval ).Should (ContainElement (harness .finalizerName ))
351
-
352
371
})
353
372
It ("Sets the correct database URL for the MariaDBAccount" , func () {
354
373
oldAccountName := types.NamespacedName {
@@ -368,25 +387,24 @@ func (harness *MariaDBTestHarness) RunURLAssertSuite(assertURL assertsURL) {
368
387
369
388
It ("Updates the database URL when the MariaDBAccount changes" , func () {
370
389
371
- oldAccountName := types.NamespacedName {
372
- Name : "some-old-account" ,
373
- Namespace : harness .namespace ,
374
- }
375
-
376
390
newAccountName := types.NamespacedName {
377
391
Name : "some-new-account" ,
378
392
Namespace : harness .namespace ,
379
393
}
380
394
381
- harness .UpdateAccount (newAccountName )
382
- harness .mariaDBHelper .SimulateMariaDBAccountCompleted (newAccountName )
395
+ mariaDBHelper := harness .mariaDBHelper
383
396
384
- mariadbAccount := harness .mariaDBHelper .GetMariaDBAccount (newAccountName )
385
- mariadbSecret := harness .mariaDBHelper .GetSecret (types.NamespacedName {Name : mariadbAccount .Spec .Secret , Namespace : mariadbAccount .Namespace })
397
+ k8sClient := mariaDBHelper .K8sClient
398
+
399
+ // create MariaDBAccount / secret ahead of time, to suit controllers
400
+ // that dont directly do EnsureMariaDBAccount
401
+ mariadbAccount , mariadbSecret := mariaDBHelper .CreateMariaDBAccountAndSecret (newAccountName , mariadbv1.MariaDBAccountSpec {})
402
+ DeferCleanup (k8sClient .Delete , mariaDBHelper .Ctx , mariadbSecret )
403
+ DeferCleanup (k8sClient .Delete , mariaDBHelper .Ctx , mariadbAccount )
386
404
387
- harness .runAccountUpdateWithWait (oldAccountName , newAccountName )
405
+ harness .UpdateAccount (newAccountName )
406
+ harness .mariaDBHelper .SimulateMariaDBAccountCompleted (newAccountName )
388
407
389
- // ensure new URL present
390
408
assertURL (
391
409
newAccountName ,
392
410
mariadbAccount .Spec .UserName ,
@@ -422,28 +440,29 @@ func (harness *MariaDBTestHarness) RunConfigHashSuite(getConfigHash getsConfigHa
422
440
423
441
It ("Gets a config hash when the MariaDBAccount is complete" , func () {
424
442
configHash := getConfigHash ()
425
- Expect (configHash ).NotTo (Equal ("" ))
443
+ Eventually (func (g Gomega ) {
444
+ g .Expect (configHash ).NotTo (Equal ("" ))
445
+ }).Should (Succeed ())
446
+
426
447
})
427
448
428
449
It ("Updates the config hash when the MariaDBAccount changes" , func () {
429
450
430
- oldAccountName := types.NamespacedName {
431
- Name : "some-old-account" ,
432
- Namespace : harness .namespace ,
433
- }
434
-
435
451
newAccountName := types.NamespacedName {
436
452
Name : "some-new-account" ,
437
453
Namespace : harness .namespace ,
438
454
}
439
455
440
456
oldConfigHash := getConfigHash ()
441
457
442
- harness .runAccountUpdateWithWait (oldAccountName , newAccountName )
458
+ harness .UpdateAccount (newAccountName )
459
+ harness .mariaDBHelper .SimulateMariaDBAccountCompleted (newAccountName )
443
460
444
- newConfigHash := getConfigHash ()
445
- Expect (newConfigHash ).NotTo (Equal ("" ))
446
- Expect (newConfigHash ).NotTo (Equal (oldConfigHash ))
461
+ Eventually (func (g Gomega ) {
462
+ newConfigHash := getConfigHash ()
463
+ g .Expect (newConfigHash ).NotTo (Equal ("" ))
464
+ g .Expect (newConfigHash ).NotTo (Equal (oldConfigHash ))
465
+ }).Should (Succeed ())
447
466
448
467
})
449
468
@@ -453,28 +472,3 @@ func (harness *MariaDBTestHarness) RunConfigHashSuite(getConfigHash getsConfigHa
453
472
func (harness * MariaDBTestHarness ) init () {
454
473
harness .PopulateHarness (harness )
455
474
}
456
-
457
- func (harness * MariaDBTestHarness ) runAccountUpdateWithWait (oldAccountName types.NamespacedName , newAccountName types.NamespacedName ) {
458
- mariaDBHelper , timeout , interval := harness .mariaDBHelper , harness .timeout , harness .interval
459
-
460
- harness .UpdateAccount (newAccountName )
461
- harness .mariaDBHelper .SimulateMariaDBAccountCompleted (newAccountName )
462
-
463
- mariaDBHelper .Logger .Info (
464
- fmt .Sprintf ("Service should move to run fully off MariaDBAccount %s and remove finalizer from %s" ,
465
- newAccountName , oldAccountName ),
466
- )
467
-
468
- // finalizer is attached to new account
469
- Eventually (func () []string {
470
- newMariadbAccount := mariaDBHelper .GetMariaDBAccount (newAccountName )
471
- return newMariadbAccount .Finalizers
472
- }, timeout , interval ).Should (ContainElement (harness .finalizerName ))
473
-
474
- // finalizer removed from old account
475
- Eventually (func () []string {
476
- oldMariadbAccount := mariaDBHelper .GetMariaDBAccount (oldAccountName )
477
- return oldMariadbAccount .Finalizers
478
- }, timeout , interval ).ShouldNot (ContainElement (harness .finalizerName ))
479
-
480
- }
0 commit comments