MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / newUserExampleHandler

Function newUserExampleHandler

internal/handler/userExample_test.go:24–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22)
23
24func newUserExampleHandler() *gotest.Handler {
25 testData := &model.UserExample{}
26 testData.ID = 1
27 // you can set the other fields of testData here, such as:
28 //testData.CreatedAt = time.Now()
29 //testData.UpdatedAt = testData.CreatedAt
30
31 // init mock cache
32 c := gotest.NewCache(map[string]interface{}{utils.Uint64ToStr(testData.ID): testData})
33 c.ICache = cache.NewUserExampleCache(&database.CacheType{
34 CType: "redis",
35 Rdb: c.RedisClient,
36 })
37
38 // init mock dao
39 d := gotest.NewDao(c, testData)
40 d.IDao = dao.NewUserExampleDao(d.DB, c.ICache.(cache.UserExampleCache))
41
42 // init mock handler
43 h := gotest.NewHandler(d, testData)
44 h.IHandler = &userExampleHandler{iDao: d.IDao.(dao.UserExampleDao)}
45 iHandler := h.IHandler.(UserExampleHandler)
46
47 testFns := []gotest.RouterInfo{
48 {
49 FuncName: "Create",
50 Method: http.MethodPost,
51 Path: "/userExample",
52 HandlerFunc: iHandler.Create,
53 },
54 {
55 FuncName: "DeleteByID",
56 Method: http.MethodDelete,
57 Path: "/userExample/:id",
58 HandlerFunc: iHandler.DeleteByID,
59 },
60 {
61 FuncName: "UpdateByID",
62 Method: http.MethodPut,
63 Path: "/userExample/:id",
64 HandlerFunc: iHandler.UpdateByID,
65 },
66 {
67 FuncName: "GetByID",
68 Method: http.MethodGet,
69 Path: "/userExample/:id",
70 HandlerFunc: iHandler.GetByID,
71 },
72 {
73 FuncName: "List",
74 Method: http.MethodPost,
75 Path: "/userExample/list",
76 HandlerFunc: iHandler.List,
77 },
78 }
79
80 h.GoRunHTTPServer(testFns)
81

Calls 7

GoRunHTTPServerMethod · 0.95
NewCacheFunction · 0.92
Uint64ToStrFunction · 0.92
NewUserExampleCacheFunction · 0.92
NewDaoFunction · 0.92
NewUserExampleDaoFunction · 0.92
NewHandlerFunction · 0.92

Tested by

no test coverage detected