Browse Source

style: TestMain

2637309949 4 years ago
parent
commit
8e5905d24e
1 changed files with 10 additions and 4 deletions
  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))
 }