monkey_dao.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package mock
  2. import (
  3. "context"
  4. "go-common/app/admin/main/apm/dao"
  5. cml "go-common/app/admin/main/apm/model/canal"
  6. "go-common/app/admin/main/apm/model/need"
  7. "go-common/app/admin/main/apm/model/ecode"
  8. "go-common/app/admin/main/apm/model/pprof"
  9. "go-common/app/admin/main/apm/model/ut"
  10. "reflect"
  11. "github.com/bouk/monkey"
  12. )
  13. // MockDaoSetConfigID .
  14. func MockDaoSetConfigID(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  15. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SetConfigID", func(_ *dao.Dao, _ int64, _ string) error {
  16. return err
  17. })
  18. }
  19. // MockDaoCanalInfoCounts .
  20. func MockDaoCanalInfoCounts(d *dao.Dao, cnt int, err error) (guard *monkey.PatchGuard) {
  21. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalInfoCounts", func(_ *dao.Dao, _ *cml.ConfigReq) (int, error) {
  22. return cnt, err
  23. })
  24. }
  25. // MockDaoCanalInfoEdit .
  26. func MockDaoCanalInfoEdit(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  27. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalInfoEdit", func(_ *dao.Dao, _ *cml.ConfigReq) error {
  28. return err
  29. })
  30. }
  31. // MockDaoCanalApplyCounts .
  32. func MockDaoCanalApplyCounts(d *dao.Dao, cnt int, err error) (guard *monkey.PatchGuard) {
  33. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyCounts", func(_ *dao.Dao, _ *cml.ConfigReq) (int, error) {
  34. return cnt, err
  35. })
  36. }
  37. // MockDaoCanalApplyEdit .
  38. func MockDaoCanalApplyEdit(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  39. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyEdit", func(_ *dao.Dao, _ *cml.ConfigReq, _ string) error {
  40. return err
  41. })
  42. }
  43. // MockDaoCanalApplyCreate .
  44. func MockDaoCanalApplyCreate(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  45. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyCreate", func(_ *dao.Dao, _ *cml.ConfigReq, _ string) error {
  46. return err
  47. })
  48. }
  49. // MockDaoGetCodes .
  50. func MockDaoGetCodes(d *dao.Dao, data []*codes.Codes, err error) (guard *monkey.PatchGuard) {
  51. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetCodes", func(_ *dao.Dao, _ context.Context, _ string, _ string) ([]*codes.Codes, error) {
  52. return data, err
  53. })
  54. }
  55. // MockDaoNeedInfoAdd .
  56. func MockDaoNeedInfoAdd(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  57. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoAdd", func(_ *dao.Dao, _ *need.NAddReq, _ string) error {
  58. return err
  59. })
  60. }
  61. // MockDaoNeedInfoList .
  62. func MockDaoNeedInfoList(d *dao.Dao, res []*need.NInfo, err error) (guard *monkey.PatchGuard) {
  63. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoList", func(_ *dao.Dao, _ *need.NListReq) ([]*need.NInfo, error) {
  64. return res, err
  65. })
  66. }
  67. // MockDaoNeedInfoCount .
  68. func MockDaoNeedInfoCount(d *dao.Dao, count int64, err error) (guard *monkey.PatchGuard) {
  69. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoCount", func(_ *dao.Dao, _ *need.NListReq) (int64, error) {
  70. return count, err
  71. })
  72. }
  73. // MockDaoGetNeedInfo .
  74. func MockDaoGetNeedInfo(d *dao.Dao, r *need.NInfo, err error) (guard *monkey.PatchGuard) {
  75. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetNeedInfo", func(_ *dao.Dao, _ int64) (*need.NInfo, error) {
  76. return r, err
  77. })
  78. }
  79. // MockDaoNeedInfoEdit .
  80. func MockDaoNeedInfoEdit(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  81. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoEdit", func(_ *dao.Dao, _ *need.NEditReq) error {
  82. return err
  83. })
  84. }
  85. // MockDaoNeedVerify .
  86. func MockDaoNeedVerify(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  87. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedVerify", func(_ *dao.Dao, _ *need.NVerifyReq) error {
  88. return err
  89. })
  90. }
  91. // MockDaoLikeCountsStats .
  92. func MockDaoLikeCountsStats(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  93. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "LikeCountsStats", func(_ *dao.Dao, _ *need.Likereq, _ int, _ int) error {
  94. return err
  95. })
  96. }
  97. // MockDaoGetVoteInfo .
  98. func MockDaoGetVoteInfo(d *dao.Dao, u *need.UserLikes, err error) (guard *monkey.PatchGuard) {
  99. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetVoteInfo", func(_ *dao.Dao, _ *need.Likereq, _ string) (*need.UserLikes, error) {
  100. return u, err
  101. })
  102. }
  103. // MockDaoUpdateVoteInfo .
  104. func MockDaoUpdateVoteInfo(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  105. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateVoteInfo", func(_ *dao.Dao, _ *need.Likereq, _ string) error {
  106. return err
  107. })
  108. }
  109. // MockDaoAddVoteInfo .
  110. func MockDaoAddVoteInfo(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  111. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "AddVoteInfo", func(_ *dao.Dao, _ *need.Likereq, _ string) error {
  112. return err
  113. })
  114. }
  115. // MockDaoVoteInfoList .
  116. func MockDaoVoteInfoList(d *dao.Dao, res []*need.UserLikes, err error) (guard *monkey.PatchGuard) {
  117. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "VoteInfoList", func(_ *dao.Dao, _ *need.Likereq) ([]*need.UserLikes, error) {
  118. return res, err
  119. })
  120. }
  121. // MockDaoVoteInfoCounts .
  122. func MockDaoVoteInfoCounts(d *dao.Dao, count int64, err error) (guard *monkey.PatchGuard) {
  123. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "VoteInfoCounts", func(_ *dao.Dao, _ *need.Likereq) (int64, error) {
  124. return count, err
  125. })
  126. }
  127. // MockDaoInstances .
  128. func MockDaoInstances(d *dao.Dao, ins *pprof.Ins, err error) (guard *monkey.PatchGuard) {
  129. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "Instances", func(_ *dao.Dao, _ context.Context, _ string) (*pprof.Ins, error) {
  130. return ins, err
  131. })
  132. }
  133. // MockDaoGitLabFace .
  134. func MockDaoGitLabFace(d *dao.Dao, avatarURL string, err error) (guard *monkey.PatchGuard) {
  135. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GitLabFace", func(_ *dao.Dao, _ context.Context, _ string) (string, error) {
  136. return avatarURL, err
  137. })
  138. }
  139. // MockDaoUploadProxy .
  140. func MockDaoUploadProxy(d *dao.Dao, url string, err error) (guard *monkey.PatchGuard) {
  141. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UploadProxy", func(_ *dao.Dao, _ context.Context, _ string, _ int64, _ []byte) (string, error) {
  142. return url, err
  143. })
  144. }
  145. // MockDaoParseUTFiles .
  146. func MockDaoParseUTFiles(d *dao.Dao, pkgs []*ut.PkgAnls, err error) (guard *monkey.PatchGuard) {
  147. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "ParseUTFiles", func(_ *dao.Dao, _ context.Context, _ string) ([]*ut.PkgAnls, error) {
  148. return pkgs, err
  149. })
  150. }
  151. // MockDaoSendWechatToUsers .
  152. func MockDaoSendWechatToUsers(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  153. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SendWechatToUsers", func(_ *dao.Dao, _ context.Context, _ []string, _ string) error {
  154. return err
  155. })
  156. }
  157. // MockDaoSendWechatToGroup .
  158. func MockDaoSendWechatToGroup(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  159. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SendWechatToGroup", func(_ *dao.Dao, _ context.Context, _ string, _ string) error {
  160. return err
  161. })
  162. }
  163. // MockDaoGitLabCommits .
  164. func MockDaoGitLabCommits(d *dao.Dao, commit *ut.GitlabCommit, err error) (guard *monkey.PatchGuard) {
  165. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GitLabCommits", func(_ *dao.Dao, _ context.Context, _ string) (*ut.GitlabCommit, error) {
  166. return commit, err
  167. })
  168. }
  169. // MockDaoGetCoverage .
  170. func MockDaoGetCoverage(d *dao.Dao, cov float64, err error) (guard *monkey.PatchGuard) {
  171. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetCoverage", func(_ *dao.Dao, _ context.Context, _ string, _ string) (float64, error) {
  172. return cov, err
  173. })
  174. }
  175. // MockDaoSetAppCovCache .
  176. func MockDaoSetAppCovCache(d *dao.Dao, err error) (guard *monkey.PatchGuard) {
  177. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SetAppCovCache", func(_ *dao.Dao, _ context.Context) error {
  178. return err
  179. })
  180. }
  181. // MockDaoGetAppCovCache .
  182. func MockDaoGetAppCovCache(d *dao.Dao, coverage float64, err error) (guard *monkey.PatchGuard) {
  183. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetAppCovCache", func(_ *dao.Dao, _ context.Context, _ string) (float64, error) {
  184. return coverage, err
  185. })
  186. }