Tests: Allow defer in TestMain

This commit is contained in:
Keith Martin 2025-11-23 22:34:50 +10:00
parent 8b865887f2
commit 404e8005fe
28 changed files with 311 additions and 227 deletions

View file

@ -15,7 +15,12 @@ import (
var assetsPath = fs.Abs("../../../assets")
var examplesPath = filepath.Join(assetsPath, "examples")
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -27,7 +32,5 @@ func TestMain(m *testing.M) {
ServiceUri = ""
// Run unit tests.
code := m.Run()
os.Exit(code)
return m.Run()
}

View file

@ -20,7 +20,12 @@ import (
"github.com/photoprism/photoprism/pkg/http/header"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -31,23 +36,22 @@ func TestMain(m *testing.M) {
// Init test config.
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
// Increase login rate limit for testing.
limiter.Login = limiter.NewLimit(1, 10000)
// Run unit tests.
code := m.Run()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}
type CloseableResponseRecorder struct {

View file

@ -10,7 +10,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -18,7 +23,5 @@ func TestMain(m *testing.M) {
AllowedPaths = append(AllowedPaths, fs.Abs("./testdata"))
// Run unit tests.
code := m.Run()
os.Exit(code)
return m.Run()
}

View file

@ -11,19 +11,25 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
// Run unit tests.
code := m.Run()
// Remove temporary SQLite files after running the tests.
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
// Run unit tests.
return m.Run()
}
func newTestConfig(t *testing.T) *cfg.Config {

View file

@ -9,14 +9,17 @@ import (
"github.com/photoprism/photoprism/internal/event"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
// Run unit tests.
code := m.Run()
os.Exit(code)
return m.Run()
}

View file

@ -11,22 +11,25 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
code := m.Run()
// Remove temporary SQLite files after running the tests.
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -21,7 +21,12 @@ import (
// "config: database not connected" during test runs, consider moving shutdown
// behavior behind an interface or gating it for tests.
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
_ = os.Setenv("TF_CPP_MIN_LOG_LEVEL", "3")
log = logrus.StandardLogger()
@ -35,8 +40,18 @@ func TestMain(m *testing.M) {
if err != nil {
panic(err)
}
defer os.RemoveAll(tempDir)
c := config.NewMinimalTestConfigWithDb("commands", tempDir)
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
// Keep DB connection open for the duration of this package's tests to
@ -48,19 +63,7 @@ func TestMain(m *testing.M) {
}
// Run unit tests.
code := m.Run()
if err = c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
_ = os.RemoveAll(tempDir)
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.RemoveAll(tempDir) // os.Exit prevents defer from executing.
os.Exit(code)
return m.Run()
}
// NewTestContext creates a new CLI test context with the flags and arguments provided.

View file

@ -22,24 +22,27 @@ func init() {
hub.ApplyTestConfig()
}
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
_ = os.Setenv("PHOTOPRISM_TEST", "true")
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
c := TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
code := m.Run()
// Remove temporary SQLite files after running the tests.
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}
func TestNewConfig(t *testing.T) {

View file

@ -11,26 +11,27 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
db := InitTestDb(
os.Getenv("PHOTOPRISM_TEST_DRIVER"),
os.Getenv("PHOTOPRISM_TEST_DSN"))
defer db.Close()
code := m.Run()
// Remove temporary SQLite files after running the tests.
db.Close()
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}
func TestTypeString(t *testing.T) {

View file

@ -11,25 +11,26 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
db := entity.InitTestDb(
os.Getenv("PHOTOPRISM_TEST_DRIVER"),
os.Getenv("PHOTOPRISM_TEST_DSN"))
defer db.Close()
code := m.Run()
// Remove temporary SQLite files after running the tests.
db.Close()
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}
func TestDbDialect(t *testing.T) {

View file

@ -10,23 +10,24 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
db := entity.InitTestDb(
os.Getenv("PHOTOPRISM_TEST_DRIVER"),
os.Getenv("PHOTOPRISM_TEST_DSN"))
defer db.Close()
code := m.Run()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}

View file

@ -7,10 +7,14 @@ import (
"github.com/sirupsen/logrus"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
code := m.Run()
os.Exit(code)
return m.Run()
}

View file

@ -13,7 +13,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
@ -22,19 +27,17 @@ func TestMain(m *testing.M) {
fs.PurgeTestDbFiles(".", false)
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
photoprism.SetConfig(c)
code := m.Run()
// Remove temporary SQLite files after running the tests.
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -8,13 +8,19 @@ import (
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
"github.com/photoprism/photoprism/internal/mutex"
"github.com/photoprism/photoprism/internal/photoprism"
"github.com/photoprism/photoprism/internal/photoprism/get"
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain configures shared state for the batch action tests.
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
// testMain configures shared state for the batch action tests.
func testMain(m *testing.M) (code int) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
@ -23,18 +29,18 @@ func TestMain(m *testing.M) {
fs.PurgeTestDbFiles(".", false)
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
// Prevent UpdateCountsAsync from causing the test suite to fail due to the database closing before the goroutine has finished.
mutex.Index.Lock()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
photoprism.SetConfig(c)
code := m.Run()
// Remove temporary SQLite files after running the tests.
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}

View file

@ -8,28 +8,29 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
tempDir, err := os.MkdirTemp("", "internal-photoprism-get")
if err != nil {
panic(err)
}
defer os.RemoveAll(tempDir)
c := config.NewMinimalTestConfigWithDb("test", tempDir)
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
SetConfig(c)
code := m.Run()
if err = c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
if err = os.RemoveAll(tempDir); err != nil {
log.Errorf("remove temp dir: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.RemoveAll(tempDir)
os.Exit(code)
return m.Run()
}

View file

@ -10,7 +10,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -20,16 +25,14 @@ func TestMain(m *testing.M) {
c := config.NewTestConfig("photoprism")
config.OnceTestConfig(c)
SetConfig(c)
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
code := m.Run()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -13,7 +13,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
// Init test logger.
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -24,21 +29,20 @@ func TestMain(m *testing.M) {
// Init test config.
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
// Increase login rate limit for testing.
limiter.Login = limiter.NewLimit(1, 10000)
// Run unit tests.
code := m.Run()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -8,19 +8,23 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
c := config.TestConfig()
defer c.CloseDb()
defer c.CleanupTestFolder()
defer func() {
c.CloseDb()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
// Run unit tests.
code := m.Run()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -7,16 +7,18 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
func testMain(m *testing.M) int {
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
// Run unit tests.
code := m.Run()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}

View file

@ -7,16 +7,18 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
func testMain(m *testing.M) int {
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
// Run unit tests.
code := m.Run()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}

View file

@ -14,18 +14,20 @@ import (
"github.com/photoprism/photoprism/pkg/rnd"
)
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
// TestMain ensures SQLite test DB artifacts are purged after the suite runs.
func testMain(m *testing.M) int {
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
// Remove temporary SQLite files after running the tests.
defer fs.PurgeTestDbFiles(".", false)
// Run unit tests.
code := m.Run()
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.Exit(code)
return m.Run()
}
func TestClientRegistry_GetAndDelete(t *testing.T) {

View file

@ -13,15 +13,18 @@ import (
"github.com/stretchr/testify/assert"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
ApplyTestConfig()
code := m.Run()
os.Exit(code)
return m.Run()
}
// Token returns a random token with length of up to 10 characters.

View file

@ -12,7 +12,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
@ -20,22 +25,19 @@ func TestMain(m *testing.M) {
if err != nil {
panic(err)
}
defer os.RemoveAll(tempDir)
c := config.NewMinimalTestConfigWithDb("avatar", tempDir)
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
photoprism.SetConfig(c)
code := m.Run()
if err = c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
_ = os.RemoveAll(tempDir)
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
os.RemoveAll(tempDir)
os.Exit(code)
return m.Run()
}

View file

@ -10,21 +10,23 @@ import (
"github.com/photoprism/photoprism/internal/event"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
code := m.Run()
Shutdown()
defer Shutdown()
// Remove generated test files and folders.
_ = os.RemoveAll("testdata/1")
_ = os.RemoveAll("testdata/cache")
_ = os.RemoveAll("testdata/vips")
defer os.RemoveAll("testdata/1")
defer os.RemoveAll("testdata/cache")
defer os.RemoveAll("testdata/vips")
os.Exit(code)
return m.Run()
}
func TestNew(t *testing.T) {

View file

@ -10,24 +10,30 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
c := config.TestConfig()
// Run unit tests.
code := m.Run()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
// Remove temporary SQLite files before running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
// Run unit tests.
return m.Run()
}
func TestStart(t *testing.T) {

View file

@ -13,7 +13,12 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) (code int) {
log = logrus.StandardLogger()
log.SetLevel(logrus.TraceLevel)
event.AuditLog = log
@ -22,20 +27,18 @@ func TestMain(m *testing.M) {
fs.PurgeTestDbFiles(".", false)
c := config.TestConfig()
defer c.CleanupTestFolder()
defer func() {
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
}()
get.SetConfig(c)
photoprism.SetConfig(c)
// Run unit tests.
code := m.Run()
if err := c.CloseDb(); err != nil {
log.Errorf("close db: %v", err)
}
// Remove temporary SQLite files after running the tests.
fs.PurgeTestDbFiles(".", false)
c.CleanupTestFolder()
os.Exit(code)
return m.Run()
}

View file

@ -13,16 +13,19 @@ import (
"github.com/stretchr/testify/assert"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
if insensitive, err := CaseInsensitive(os.TempDir()); err != nil {
fmt.Println(err)
} else if insensitive {
IgnoreCase()
}
code := m.Run()
os.Exit(code)
return m.Run()
}
func TestExists(t *testing.T) {

View file

@ -8,12 +8,15 @@ import (
"github.com/stretchr/testify/assert"
)
// TestMain executes testMain returning it's results. It is done this way so that defer can be used to cleanup.
func TestMain(m *testing.M) {
os.Exit(testMain(m))
}
func testMain(m *testing.M) int {
gotext.Configure(localeDir, string(locale), "default")
code := m.Run()
os.Exit(code)
return m.Run()
}
func TestMsg(t *testing.T) {