Skip to content

Commit

Permalink
NOISSUE - Remove defers from TestMain (#1111)
Browse files Browse the repository at this point in the history
Defers will not be run when using os.Exit (golang/go#34129)

Signed-off-by: Alexander Obukhov <dev@sprql.space>
  • Loading branch information
sprql authored Apr 14, 2020
1 parent 5b52299 commit fbbf2c0
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion authn/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func TestMain(m *testing.M) {
if db, err = postgres.Connect(dbConfig); err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err := pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion bootstrap/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ func TestMain(m *testing.M) {
if db, err = postgres.Connect(dbConfig); err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err := pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion readers/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func TestMain(m *testing.M) {
if db, err = postgres.Connect(dbConfig); err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err = pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion things/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func TestMain(m *testing.M) {
if db, err = postgres.Connect(dbConfig); err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err := pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion users/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ func TestMain(m *testing.M) {
if db, err = postgres.Connect(dbConfig); err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err := pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down
3 changes: 2 additions & 1 deletion writers/postgres/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ func TestMain(m *testing.M) {
if err != nil {
log.Fatalf("Could not setup test DB connection: %s", err)
}
defer db.Close()

code := m.Run()

// defers will not be run when using os.Exit
db.Close()
if err := pool.Purge(container); err != nil {
log.Fatalf("Could not purge container: %s", err)
}
Expand Down

0 comments on commit fbbf2c0

Please sign in to comment.