Skip to content

Commit

Permalink
pool: Leave failed postgres db state in pool tests.
Browse files Browse the repository at this point in the history
This modifies the pool tests to avoid cleaning up the postgres data when
there is a test failure so the contents of the database can be examined.

Since a failed run will no longer purge the data, it also adds log to
purge the data prior to running the tests to ensure any previous failed
runs are cleaned up on subsequent runs.
  • Loading branch information
davecgh committed Sep 20, 2023
1 parent adc5c16 commit b2added
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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 {
if t.Failed() {
Expand All @@ -147,9 +158,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() {
err = postgresDB.purge()
if err != nil {
t.Fatalf("postgres teardown error: %v", err)
}
}

postgresDB.Close()
Expand Down

0 comments on commit b2added

Please sign in to comment.