split up test initialization code
This commit is contained in:
parent
7e51ffbe82
commit
3eddc018d9
19
testing.go
19
testing.go
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user