()
| 25 | ) |
| 26 | |
| 27 | func newUserExamplePbHandler() *gotest.Handler { |
| 28 | testData := &model.UserExample{} |
| 29 | testData.ID = 1 |
| 30 | // you can set the other fields of testData here, such as: |
| 31 | //testData.CreatedAt = time.Now() |
| 32 | //testData.UpdatedAt = testData.CreatedAt |
| 33 | |
| 34 | // init mock cache |
| 35 | c := gotest.NewCache(map[string]interface{}{utils.Uint64ToStr(testData.ID): testData}) |
| 36 | c.ICache = cache.NewUserExampleCache(&database.CacheType{ |
| 37 | CType: "redis", |
| 38 | Rdb: c.RedisClient, |
| 39 | }) |
| 40 | |
| 41 | // init mock dao |
| 42 | d := gotest.NewDao(c, testData) |
| 43 | d.IDao = dao.NewUserExampleDao(d.DB, c.ICache.(cache.UserExampleCache)) |
| 44 | |
| 45 | // init mock handler |
| 46 | h := gotest.NewHandler(d, testData) |
| 47 | h.IHandler = &userExamplePbHandler{userExampleDao: d.IDao.(dao.UserExampleDao)} |
| 48 | iHandler := h.IHandler.(serverNameExampleV1.UserExampleLogicer) |
| 49 | |
| 50 | testFns := []gotest.RouterInfo{ |
| 51 | { |
| 52 | FuncName: "Create", |
| 53 | Method: http.MethodPost, |
| 54 | Path: "/userExample", |
| 55 | HandlerFunc: func(c *gin.Context) { |
| 56 | req := &serverNameExampleV1.CreateUserExampleRequest{} |
| 57 | _ = c.ShouldBindJSON(req) |
| 58 | _, err := iHandler.Create(c, req) |
| 59 | if err != nil { |
| 60 | response.Error(c, ecode.ErrCreateUserExample) |
| 61 | return |
| 62 | } |
| 63 | response.Success(c) |
| 64 | }, |
| 65 | }, |
| 66 | { |
| 67 | FuncName: "DeleteByID", |
| 68 | Method: http.MethodDelete, |
| 69 | Path: "/userExample/:id", |
| 70 | HandlerFunc: func(c *gin.Context) { |
| 71 | req := &serverNameExampleV1.DeleteUserExampleByIDRequest{ |
| 72 | Id: utils.StrToUint64(c.Param("id")), |
| 73 | } |
| 74 | _, err := iHandler.DeleteByID(c, req) |
| 75 | if err != nil { |
| 76 | response.Error(c, ecode.ErrDeleteByIDUserExample) |
| 77 | return |
| 78 | } |
| 79 | response.Success(c) |
| 80 | }, |
| 81 | }, |
| 82 | { |
| 83 | FuncName: "UpdateByID", |
| 84 | Method: http.MethodPut, |
no test coverage detected