()
| 22 | ) |
| 23 | |
| 24 | func 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 |
no test coverage detected