@@ -415,10 +415,12 @@ func getSqlStoreEngine(ctx context.Context, store *SqlStore, kind types.Engine)
415
415
}
416
416
417
417
func newReusedPostgresStore (ctx context.Context , store * SqlStore , kind types.Engine ) (* SqlStore , func (), error ) {
418
+ var containerCleanup , dbCleanup func ()
419
+
418
420
dsn , ok := os .LookupEnv (postgresDsnEnv )
419
421
if ! ok || dsn == "" {
420
422
var err error
421
- _ , dsn , err = testutil .CreatePostgresTestContainer ()
423
+ containerCleanup , dsn , err = testutil .CreatePostgresTestContainer ()
422
424
if err != nil {
423
425
return nil , nil , err
424
426
}
@@ -433,24 +435,33 @@ func newReusedPostgresStore(ctx context.Context, store *SqlStore, kind types.Eng
433
435
return nil , nil , fmt .Errorf ("failed to open postgres connection: %v" , err )
434
436
}
435
437
436
- dsn , cleanup , err : = createRandomDB (dsn , db , kind )
438
+ dsn , dbCleanup , err = createRandomDB (dsn , db , kind )
437
439
if err != nil {
438
- return nil , cleanup , err
440
+ return nil , nil , err
439
441
}
440
442
441
443
store , err = NewPostgresqlStoreFromSqlStore (ctx , store , dsn , nil )
442
444
if err != nil {
443
- return nil , cleanup , err
445
+ return nil , nil , err
446
+ }
447
+
448
+ cleanup := func () {
449
+ if containerCleanup != nil {
450
+ containerCleanup ()
451
+ }
452
+ dbCleanup ()
444
453
}
445
454
446
455
return store , cleanup , nil
447
456
}
448
457
449
458
func newReusedMysqlStore (ctx context.Context , store * SqlStore , kind types.Engine ) (* SqlStore , func (), error ) {
459
+ var containerCleanup , dbCleanup func ()
460
+
450
461
dsn , ok := os .LookupEnv (mysqlDsnEnv )
451
462
if ! ok || dsn == "" {
452
463
var err error
453
- _ , dsn , err = testutil .CreateMysqlTestContainer ()
464
+ containerCleanup , dsn , err = testutil .CreateMysqlTestContainer ()
454
465
if err != nil {
455
466
return nil , nil , err
456
467
}
@@ -465,16 +476,23 @@ func newReusedMysqlStore(ctx context.Context, store *SqlStore, kind types.Engine
465
476
return nil , nil , fmt .Errorf ("failed to open mysql connection: %v" , err )
466
477
}
467
478
468
- dsn , cleanup , err : = createRandomDB (dsn , db , kind )
479
+ dsn , dbCleanup , err = createRandomDB (dsn , db , kind )
469
480
if err != nil {
470
- return nil , cleanup , err
481
+ return nil , nil , err
471
482
}
472
483
473
484
store , err = NewMysqlStoreFromSqlStore (ctx , store , dsn , nil )
474
485
if err != nil {
475
486
return nil , nil , err
476
487
}
477
488
489
+ cleanup := func () {
490
+ if containerCleanup != nil {
491
+ containerCleanup ()
492
+ }
493
+ dbCleanup ()
494
+ }
495
+
478
496
return store , cleanup , nil
479
497
}
480
498
0 commit comments