From e703a54586ec0bac0ffc89fa9a1e24aa96b3be8a Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 8 May 2020 18:35:19 +0200 Subject: [PATCH] Backend: Close db connection after running tests Signed-off-by: Michael Mayer --- internal/api/api_test.go | 16 ++++++++++++++++ internal/config/config_test.go | 15 +++++++++++++++ internal/photoprism/photoprism_test.go | 8 +++----- internal/service/service_test.go | 2 ++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/internal/api/api_test.go b/internal/api/api_test.go index d57da7c5f..73f98c120 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -3,11 +3,14 @@ package api import ( "net/http" "net/http/httptest" + "os" "strings" + "testing" "github.com/gin-gonic/gin" "github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/internal/service" + "github.com/sirupsen/logrus" ) // NewApiTest returns new API test helper @@ -37,3 +40,16 @@ func PerformRequestWithBody(r http.Handler, method, path, body string) *httptest r.ServeHTTP(w, req) return w } + +func TestMain(m *testing.M) { + log = logrus.StandardLogger() + log.SetLevel(logrus.DebugLevel) + + c := config.TestConfig() + + code := m.Run() + + _ = c.CloseDb() + + os.Exit(code) +} diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 7433bfbdc..f1dea6191 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1,13 +1,28 @@ package config import ( + "os" "strings" "testing" "github.com/photoprism/photoprism/pkg/fs" + "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) +func TestMain(m *testing.M) { + log = logrus.StandardLogger() + log.SetLevel(logrus.DebugLevel) + + c := TestConfig() + + code := m.Run() + + _ = c.CloseDb() + + os.Exit(code) +} + func TestNewConfig(t *testing.T) { ctx := CliTestContext() diff --git a/internal/photoprism/photoprism_test.go b/internal/photoprism/photoprism_test.go index de276531f..d7059640e 100644 --- a/internal/photoprism/photoprism_test.go +++ b/internal/photoprism/photoprism_test.go @@ -4,7 +4,7 @@ import ( "os" "testing" - "github.com/photoprism/photoprism/internal/entity" + "github.com/photoprism/photoprism/internal/config" "github.com/sirupsen/logrus" ) @@ -12,13 +12,11 @@ func TestMain(m *testing.M) { log = logrus.StandardLogger() log.SetLevel(logrus.DebugLevel) - db := entity.InitTestDb(os.Getenv("PHOTOPRISM_TEST_DSN")) + c := config.TestConfig() code := m.Run() - if db != nil { - db.Close() - } + _ = c.CloseDb() os.Exit(code) } diff --git a/internal/service/service_test.go b/internal/service/service_test.go index fad66e9cd..e6df7a223 100644 --- a/internal/service/service_test.go +++ b/internal/service/service_test.go @@ -21,6 +21,8 @@ func TestMain(m *testing.M) { code := m.Run() + _ = c.CloseDb() + os.Exit(code) }