Backend: Close db connection after running tests
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
2f28c6840e
commit
e703a54586
|
@ -3,11 +3,14 @@ package api
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/photoprism/photoprism/internal/config"
|
"github.com/photoprism/photoprism/internal/config"
|
||||||
"github.com/photoprism/photoprism/internal/service"
|
"github.com/photoprism/photoprism/internal/service"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewApiTest returns new API test helper
|
// NewApiTest returns new API test helper
|
||||||
|
@ -37,3 +40,16 @@ func PerformRequestWithBody(r http.Handler, method, path, body string) *httptest
|
||||||
r.ServeHTTP(w, req)
|
r.ServeHTTP(w, req)
|
||||||
return w
|
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)
|
||||||
|
}
|
||||||
|
|
|
@ -1,13 +1,28 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/pkg/fs"
|
"github.com/photoprism/photoprism/pkg/fs"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestNewConfig(t *testing.T) {
|
||||||
ctx := CliTestContext()
|
ctx := CliTestContext()
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/photoprism/photoprism/internal/entity"
|
"github.com/photoprism/photoprism/internal/config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,13 +12,11 @@ func TestMain(m *testing.M) {
|
||||||
log = logrus.StandardLogger()
|
log = logrus.StandardLogger()
|
||||||
log.SetLevel(logrus.DebugLevel)
|
log.SetLevel(logrus.DebugLevel)
|
||||||
|
|
||||||
db := entity.InitTestDb(os.Getenv("PHOTOPRISM_TEST_DSN"))
|
c := config.TestConfig()
|
||||||
|
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|
||||||
if db != nil {
|
_ = c.CloseDb()
|
||||||
db.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
|
|
||||||
|
_ = c.CloseDb()
|
||||||
|
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue