44 lines
760 B
Go
44 lines
760 B
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"os"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
. "code.hoteas.com/golang/hotime"
|
||
|
|
)
|
||
|
|
|
||
|
|
var ProjectTest = ProjTest{
|
||
|
|
"test": TestTest,
|
||
|
|
"mysql": MysqlTest,
|
||
|
|
"dmdb": DmdbTest,
|
||
|
|
"cache": CacheTest,
|
||
|
|
}
|
||
|
|
|
||
|
|
var testApp *TestApp
|
||
|
|
|
||
|
|
func TestMain(m *testing.M) {
|
||
|
|
// Go test 的 CWD 是包目录 example/app/,切回 example/ 使相对路径正确
|
||
|
|
_ = os.Chdir("..")
|
||
|
|
|
||
|
|
testApp = NewTestApp("config/config.json",
|
||
|
|
TestProj{
|
||
|
|
"app": {
|
||
|
|
Proj: Project,
|
||
|
|
Tests: ProjectTest,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
)
|
||
|
|
|
||
|
|
// 在测试前初始化各数据库的测试表和种子数据
|
||
|
|
SetupDatabase(&testApp.Db)
|
||
|
|
|
||
|
|
code := m.Run()
|
||
|
|
testApp.PrintCoverage()
|
||
|
|
testApp.GenerateSwagger("My API", "1.0.0", testApp.Config.GetString("tpt"))
|
||
|
|
os.Exit(code)
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestApi(t *testing.T) {
|
||
|
|
testApp.RunTests(t)
|
||
|
|
}
|