From ebb6bd52b22b10985d2260762418976e72537f89 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 20 Sep 2023 15:32:29 -0500 Subject: [PATCH] pool: Leave failed postgres db state in pool tests. This modifies the pool tests to avoid cleaning up the postgres data when there is a test failure and the -failfast test flag is set so the contents of the database can be examined. Since a failed run with -failfast will no longer purge the data, it also adds logic to purge the data prior to running the tests to ensure any previous failed runs are cleaned up on subsequent runs. --- pool/pool_test.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/pool/pool_test.go b/pool/pool_test.go index 9e5bf2ab..62495a86 100644 --- a/pool/pool_test.go +++ b/pool/pool_test.go @@ -5,6 +5,7 @@ package pool import ( + "flag" "os" "testing" @@ -128,6 +129,17 @@ func TestPool(t *testing.T) { boltDB.Close() } + // Cleanup postgres DB from potential failed previous runs. + postgresDB, err := setupPostgresDB() + if err != nil { + t.Fatalf("setupPostgresDB error: %v", err) + } + err = postgresDB.purge() + if err != nil { + t.Fatalf("postgres teardown error: %v", err) + } + postgresDB.Close() + // Run all tests with postgres DB. for testName, test := range tests { postgresDB, err := setupPostgresDB() @@ -139,9 +151,11 @@ func TestPool(t *testing.T) { t.Run(testName+"_Postgres", test) - err = postgresDB.purge() - if err != nil { - t.Fatalf("postgres teardown error: %v", err) + if !t.Failed() || flag.Lookup("test.failfast") == nil { + err = postgresDB.purge() + if err != nil { + t.Fatalf("postgres teardown error: %v", err) + } } postgresDB.Close()