mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
TestMain: Handle "defer" before os.Exit #5330
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
6c50a87632
commit
d023139c12
17 changed files with 66 additions and 27 deletions
|
|
@ -32,7 +32,6 @@ func TestMain(m *testing.M) {
|
|||
// Init test config.
|
||||
c := config.TestConfig()
|
||||
get.SetConfig(c)
|
||||
defer c.CloseDb()
|
||||
|
||||
// Increase login rate limit for testing.
|
||||
limiter.Login = limiter.NewLimit(1, 10000)
|
||||
|
|
@ -40,6 +39,10 @@ func TestMain(m *testing.M) {
|
|||
// 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ func TestUserPasscode(t *testing.T) {
|
|||
pcStr, err := json.Marshal(f0)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.Fatalf("marshal passcode: %v", err)
|
||||
}
|
||||
|
||||
r := AuthenticatedRequestWithBody(app, "POST", "/api/v1/users/uqxetse3cy5eo9z2/passcode", string(pcStr), sessId)
|
||||
|
|
@ -264,7 +264,7 @@ func TestUserPasscode(t *testing.T) {
|
|||
ConfirmUserPasscode(router)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
t.Fatalf("generate totp code: %v", err)
|
||||
}
|
||||
|
||||
f := form.Passcode{
|
||||
|
|
@ -276,7 +276,7 @@ func TestUserPasscode(t *testing.T) {
|
|||
pcStr, err = json.Marshal(f)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.Fatalf("marshal passcode confirm: %v", err)
|
||||
}
|
||||
|
||||
r = AuthenticatedRequestWithBody(app, "POST", "/api/v1/users/uqxetse3cy5eo9z2/passcode/confirm", string(pcStr), sessId)
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@ func TestMain(m *testing.M) {
|
|||
code := m.Run()
|
||||
|
||||
// Remove temporary SQLite files after running the tests.
|
||||
fs.PurgeTestDbFiles(".", false)
|
||||
if err := c.CloseDb(); err != nil {
|
||||
log.Fatalf("close db: %v", err)
|
||||
log.Errorf("close db: %v", err)
|
||||
}
|
||||
|
||||
fs.PurgeTestDbFiles(".", false)
|
||||
|
||||
os.Exit(code)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
c := config.NewMinimalTestConfigWithDb("commands", tempDir)
|
||||
get.SetConfig(c)
|
||||
|
|
@ -51,6 +50,12 @@ 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,14 @@ func TestMain(m *testing.M) {
|
|||
log.SetLevel(logrus.TraceLevel)
|
||||
|
||||
c := TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ func TestMain(m *testing.M) {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -22,11 +22,11 @@ func TestMain(m *testing.M) {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ func TestMain(m *testing.M) {
|
|||
fs.PurgeTestDbFiles(".", false)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
||||
get.SetConfig(c)
|
||||
photoprism.SetConfig(c)
|
||||
|
|
@ -30,6 +29,10 @@ func TestMain(m *testing.M) {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ func TestMain(m *testing.M) {
|
|||
fs.PurgeTestDbFiles(".", false)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
||||
get.SetConfig(c)
|
||||
photoprism.SetConfig(c)
|
||||
|
|
@ -31,6 +30,10 @@ func TestMain(m *testing.M) {
|
|||
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)
|
||||
|
|
|
|||
|
|
@ -13,14 +13,20 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
c := config.NewMinimalTestConfigWithDb("test", tempDir)
|
||||
|
||||
SetConfig(c)
|
||||
defer c.CloseDb()
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,9 @@ func TestJWTVerifierResetOnConfigChange(t *testing.T) {
|
|||
SetConfig(tempConf)
|
||||
t.Cleanup(func() {
|
||||
SetConfig(orig)
|
||||
tempConf.CloseDb()
|
||||
if err := tempConf.CloseDb(); err != nil {
|
||||
t.Logf("close db: %v", err)
|
||||
}
|
||||
orig.RegisterDb()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -19,10 +19,13 @@ func TestMain(m *testing.M) {
|
|||
|
||||
c := config.NewTestConfig("photoprism")
|
||||
SetConfig(c)
|
||||
defer c.CloseDb()
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ func TestMain(m *testing.M) {
|
|||
// Init test config.
|
||||
c := config.TestConfig()
|
||||
get.SetConfig(c)
|
||||
defer c.CloseDb()
|
||||
|
||||
// Increase login rate limit for testing.
|
||||
limiter.Login = limiter.NewLimit(1, 10000)
|
||||
|
|
@ -33,6 +32,10 @@ func TestMain(m *testing.M) {
|
|||
// 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)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,15 +20,19 @@ func TestMain(m *testing.M) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
c := config.NewMinimalTestConfigWithDb("avatar", tempDir)
|
||||
get.SetConfig(c)
|
||||
photoprism.SetConfig(c)
|
||||
defer c.CloseDb()
|
||||
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ func TestMain(m *testing.M) {
|
|||
log.SetLevel(logrus.TraceLevel)
|
||||
event.AuditLog = log
|
||||
|
||||
defer Shutdown()
|
||||
|
||||
code := m.Run()
|
||||
|
||||
Shutdown()
|
||||
|
||||
// Remove generated test files and folders.
|
||||
_ = os.RemoveAll("testdata/1")
|
||||
_ = os.RemoveAll("testdata/cache")
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@ func TestMain(m *testing.M) {
|
|||
log.SetLevel(logrus.TraceLevel)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
||||
// Run unit tests.
|
||||
code := m.Run()
|
||||
|
||||
// Close database connection.
|
||||
_ = c.CloseDb()
|
||||
if err := c.CloseDb(); err != nil {
|
||||
log.Errorf("close db: %v", err)
|
||||
}
|
||||
|
||||
// Remove temporary SQLite files after running the tests.
|
||||
fs.PurgeTestDbFiles(".", false)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ func TestMain(m *testing.M) {
|
|||
fs.PurgeTestDbFiles(".", false)
|
||||
|
||||
c := config.TestConfig()
|
||||
defer c.CloseDb()
|
||||
|
||||
get.SetConfig(c)
|
||||
photoprism.SetConfig(c)
|
||||
|
|
@ -30,6 +29,10 @@ func TestMain(m *testing.M) {
|
|||
// 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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue