split up test initialization code

This commit is contained in:
☙◦ The Tablet ❀ GamerGirlandCo ◦❧ 2025-07-17 14:35:42 -04:00
parent 7e51ffbe82
commit 3eddc018d9
Signed by: tablet
GPG Key ID: 924A5F6AF051E87C

View File

@ -281,7 +281,7 @@ type commonTestFunc func(t assert.TestingT)
var logTime = time.Now()
func initTest(t assert.TestingT) *Engine {
func initCommonTest(t assert.TestingT) *Engine {
f, err := os.OpenFile(
fmt.Sprintf("test-logs/test-%d.log", logTime.UnixMilli()),
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
@ -292,7 +292,19 @@ func initTest(t assert.TestingT) *Engine {
})
assert.Nil(t, err)
e.Models(user{}, story{}, band{}, role{})
err = e.MigrateDropping()
return e
}
func deleteAll(e *Engine) {
models := []any{&user{}, &story{}, &band{}, &role{}}
for _, model := range models {
e.Model(model).WhereRaw("true").Delete()
}
}
func initTest(t assert.TestingT) *Engine {
e := initCommonTest(t)
err := e.MigrateDropping()
assert.Nil(t, err)
return e
}
@ -320,8 +332,9 @@ func checkChapters(t assert.TestingT, s *story) {
func bench(fn func(assert.TestingT, *Engine)) func(b *testing.B) {
return func(b *testing.B) {
e := initTest(b)
e := initCommonTest(b)
for b.Loop() {
deleteAll(e)
fn(b, e)
}
e.Disconnect()