From fbbf2c07a5f0510ce53be0cbf7cd6a4d55f8caa5 Mon Sep 17 00:00:00 2001 From: Alexander Obukhov Date: Tue, 14 Apr 2020 15:47:34 +0300 Subject: [PATCH] NOISSUE - Remove defers from TestMain (#1111) Defers will not be run when using os.Exit (https://github.com/golang/go/issues/34129) Signed-off-by: Alexander Obukhov --- authn/postgres/setup_test.go | 3 ++- bootstrap/postgres/setup_test.go | 3 ++- readers/postgres/setup_test.go | 3 ++- things/postgres/setup_test.go | 3 ++- users/postgres/setup_test.go | 3 ++- writers/postgres/setup_test.go | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/authn/postgres/setup_test.go b/authn/postgres/setup_test.go index 288214a46d..3d8a4287e0 100644 --- a/authn/postgres/setup_test.go +++ b/authn/postgres/setup_test.go @@ -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) } diff --git a/bootstrap/postgres/setup_test.go b/bootstrap/postgres/setup_test.go index b74af967eb..22c61c254f 100644 --- a/bootstrap/postgres/setup_test.go +++ b/bootstrap/postgres/setup_test.go @@ -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) } diff --git a/readers/postgres/setup_test.go b/readers/postgres/setup_test.go index be3b4fd4cb..f29553b944 100644 --- a/readers/postgres/setup_test.go +++ b/readers/postgres/setup_test.go @@ -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) } diff --git a/things/postgres/setup_test.go b/things/postgres/setup_test.go index 171156d71c..a5790ec63f 100644 --- a/things/postgres/setup_test.go +++ b/things/postgres/setup_test.go @@ -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) } diff --git a/users/postgres/setup_test.go b/users/postgres/setup_test.go index 8a26b45215..62fd45db44 100644 --- a/users/postgres/setup_test.go +++ b/users/postgres/setup_test.go @@ -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) } diff --git a/writers/postgres/setup_test.go b/writers/postgres/setup_test.go index 1a6e9dd6ac..08c445dffe 100644 --- a/writers/postgres/setup_test.go +++ b/writers/postgres/setup_test.go @@ -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) }