瀏覽代碼

style: TestMain

2637309949 4 年之前
父節點
當前提交
8e5905d24e
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      internal/logic/user/logic_test.go

+ 10 - 4
internal/logic/user/logic_test.go

@@ -12,11 +12,17 @@ import (
 	"git.i2edu.net/i2/i2-bill-api/internal/svc"
 )
 
-func TestCreateJWT(t *testing.T) {
-	var configFile = flag.String("f", "etc/i2bill-api.yaml", "the config file")
-	var c config.Config
+var configFile = flag.String("f", "etc/i2bill-api.yaml", "the config file")
+var c config.Config
+var ctx *svc.ServiceContext
+
+// TestMain defined
+func TestMain(m *testing.M) {
 	conf.MustLoad(*configFile, &c)
-	ctx := svc.NewServiceContext(c)
+	ctx = svc.NewServiceContext(c)
+}
+
+func TestCreateJWT(t *testing.T) {
 	l := auth.NewLoginByWeixinLogic(context.TODO(), ctx)
 	fmt.Println(l.CreateJWT(1624415746, c.JwtAuth.AccessSecret, nil, 1000))
 }