/
test.go
55 lines (46 loc) · 978 Bytes
/
test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package test
import (
"context"
"net/http"
"os"
"testing"
"github.com/LyricTian/gin-admin/v10/internal/config"
"github.com/LyricTian/gin-admin/v10/internal/wirex"
"github.com/gavv/httpexpect/v2"
"github.com/gin-gonic/gin"
)
const (
baseAPI = "/api/v1"
)
var (
app *gin.Engine
)
func init() {
config.MustLoad("")
_ = os.RemoveAll(config.C.Storage.DB.DSN)
ctx := context.Background()
injector, _, err := wirex.BuildInjector(ctx)
if err != nil {
panic(err)
}
if err := injector.M.Init(ctx); err != nil {
panic(err)
}
app = gin.New()
err = injector.M.RegisterRouters(ctx, app)
if err != nil {
panic(err)
}
}
func tester(t *testing.T) *httpexpect.Expect {
return httpexpect.WithConfig(httpexpect.Config{
Client: &http.Client{
Transport: httpexpect.NewBinder(app),
Jar: httpexpect.NewCookieJar(),
},
Reporter: httpexpect.NewAssertReporter(t),
Printers: []httpexpect.Printer{
httpexpect.NewDebugPrinter(t, true),
},
})
}