monkey.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. package dao
  2. import (
  3. "context"
  4. cml "go-common/app/admin/main/apm/model/canal"
  5. "go-common/app/admin/main/apm/model/ecode"
  6. "go-common/app/admin/main/apm/model/need"
  7. "go-common/app/admin/main/apm/model/pprof"
  8. "go-common/app/admin/main/apm/model/ut"
  9. "reflect"
  10. "github.com/bouk/monkey"
  11. )
  12. //MockSetConfigID is
  13. func (d *Dao) MockSetConfigID(err error) (guard *monkey.PatchGuard) {
  14. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SetConfigID", func(_ *Dao, _ int64, _ string) error {
  15. return err
  16. })
  17. }
  18. //MockCanalInfoCounts is
  19. func (d *Dao) MockCanalInfoCounts(cnt int, err error) (guard *monkey.PatchGuard) {
  20. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalInfoCounts", func(_ *Dao, _ *cml.ConfigReq) (int, error) {
  21. return cnt, err
  22. })
  23. }
  24. //MockCanalInfoEdit is
  25. func (d *Dao) MockCanalInfoEdit(err error) (guard *monkey.PatchGuard) {
  26. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalInfoEdit", func(_ *Dao, _ *cml.ConfigReq) error {
  27. return err
  28. })
  29. }
  30. //MockCanalApplyCounts is
  31. func (d *Dao) MockCanalApplyCounts(cnt int, err error) (guard *monkey.PatchGuard) {
  32. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyCounts", func(_ *Dao, _ *cml.ConfigReq) (int, error) {
  33. return cnt, err
  34. })
  35. }
  36. //MockCanalApplyEdit is
  37. func (d *Dao) MockCanalApplyEdit(err error) (guard *monkey.PatchGuard) {
  38. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyEdit", func(_ *Dao, _ *cml.ConfigReq, _ string) error {
  39. return err
  40. })
  41. }
  42. //MockCanalApplyCreate is
  43. func (d *Dao) MockCanalApplyCreate(err error) (guard *monkey.PatchGuard) {
  44. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CanalApplyCreate", func(_ *Dao, _ *cml.ConfigReq, _ string) error {
  45. return err
  46. })
  47. }
  48. //MockGetCodes is
  49. func (d *Dao) MockGetCodes(data []*codes.Codes, err error) (guard *monkey.PatchGuard) {
  50. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetCodes", func(_ *Dao, _ context.Context, _ string, _ string) ([]*codes.Codes, error) {
  51. return data, err
  52. })
  53. }
  54. //MockNeedInfoAdd is
  55. func (d *Dao) MockNeedInfoAdd(err error) (guard *monkey.PatchGuard) {
  56. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoAdd", func(_ *Dao, _ *need.NAddReq, _ string) error {
  57. return err
  58. })
  59. }
  60. //MockNeedInfoList is
  61. func (d *Dao) MockNeedInfoList(res []*need.NInfo, err error) (guard *monkey.PatchGuard) {
  62. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoList", func(_ *Dao, _ *need.NListReq) ([]*need.NInfo, error) {
  63. return res, err
  64. })
  65. }
  66. //MockNeedInfoCount is
  67. func (d *Dao) MockNeedInfoCount(count int64, err error) (guard *monkey.PatchGuard) {
  68. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoCount", func(_ *Dao, _ *need.NListReq) (int64, error) {
  69. return count, err
  70. })
  71. }
  72. //MockGetNeedInfo is
  73. func (d *Dao) MockGetNeedInfo(r []*need.NInfo, err error) (guard *monkey.PatchGuard) {
  74. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetNeedInfo", func(_ *Dao, _ int64) ([]*need.NInfo, error) {
  75. return r, err
  76. })
  77. }
  78. //MockNeedInfoEdit is
  79. func (d *Dao) MockNeedInfoEdit(err error) (guard *monkey.PatchGuard) {
  80. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedInfoEdit", func(_ *Dao, _ *need.NEditReq) error {
  81. return err
  82. })
  83. }
  84. //MockNeedVerify is
  85. func (d *Dao) MockNeedVerify(err error) (guard *monkey.PatchGuard) {
  86. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "NeedVerify", func(_ *Dao, _ *need.NVerifyReq) error {
  87. return err
  88. })
  89. }
  90. //MockLikeCountsStats is
  91. func (d *Dao) MockLikeCountsStats(err error) (guard *monkey.PatchGuard) {
  92. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "LikeCountsStats", func(_ *Dao, _ *need.Likereq, _ int, _ int) error {
  93. return err
  94. })
  95. }
  96. //MockGetVoteInfo is
  97. func (d *Dao) MockGetVoteInfo(u []*need.UserLikes, err error) (guard *monkey.PatchGuard) {
  98. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetVoteInfo", func(_ *Dao, _ *need.Likereq, _ string) ([]*need.UserLikes, error) {
  99. return u, err
  100. })
  101. }
  102. //MockUpdateVoteInfo is
  103. func (d *Dao) MockUpdateVoteInfo(err error) (guard *monkey.PatchGuard) {
  104. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateVoteInfo", func(_ *Dao, _ *need.Likereq, _ string) error {
  105. return err
  106. })
  107. }
  108. //MockAddVoteInfo is
  109. func (d *Dao) MockAddVoteInfo(err error) (guard *monkey.PatchGuard) {
  110. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "AddVoteInfo", func(_ *Dao, _ *need.Likereq, _ string) error {
  111. return err
  112. })
  113. }
  114. //MockVoteInfoList is
  115. func (d *Dao) MockVoteInfoList(res []*need.UserLikes, err error) (guard *monkey.PatchGuard) {
  116. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "VoteInfoList", func(_ *Dao, _ *need.Likereq) ([]*need.UserLikes, error) {
  117. return res, err
  118. })
  119. }
  120. //MockVoteInfoCounts is
  121. func (d *Dao) MockVoteInfoCounts(count int64, err error) (guard *monkey.PatchGuard) {
  122. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "VoteInfoCounts", func(_ *Dao, _ *need.Likereq) (int64, error) {
  123. return count, err
  124. })
  125. }
  126. //MockInstances is
  127. func (d *Dao) MockInstances(ins *pprof.Ins, err error) (guard *monkey.PatchGuard) {
  128. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "Instances", func(_ *Dao, _ context.Context, _ string) (*pprof.Ins, error) {
  129. return ins, err
  130. })
  131. }
  132. //MockGitLabFace is
  133. func (d *Dao) MockGitLabFace(avatarURL string, err error) (guard *monkey.PatchGuard) {
  134. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GitLabFace", func(_ *Dao, _ context.Context, _ string) (string, error) {
  135. return avatarURL, err
  136. })
  137. }
  138. //MockUploadProxy is
  139. func (d *Dao) MockUploadProxy(url string, err error) (guard *monkey.PatchGuard) {
  140. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UploadProxy", func(_ *Dao, _ context.Context, _ string, _ int64, _ []byte) (string, error) {
  141. return url, err
  142. })
  143. }
  144. //MockParseUTFiles is
  145. func (d *Dao) MockParseUTFiles(pkgs []*ut.PkgAnls, err error) (guard *monkey.PatchGuard) {
  146. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "ParseUTFiles", func(_ *Dao, _ context.Context, _ string) ([]*ut.PkgAnls, error) {
  147. return pkgs, err
  148. })
  149. }
  150. //MockSendWechatToUsers is
  151. func (d *Dao) MockSendWechatToUsers(err error) (guard *monkey.PatchGuard) {
  152. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SendWechatToUsers", func(_ *Dao, _ context.Context, _ []string, _ string) error {
  153. return err
  154. })
  155. }
  156. //MockSendWechatToGroup is
  157. func (d *Dao) MockSendWechatToGroup(err error) (guard *monkey.PatchGuard) {
  158. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SendWechatToGroup", func(_ *Dao, _ context.Context, _ string, _ string) error {
  159. return err
  160. })
  161. }
  162. //MockGitLabCommits is
  163. func (d *Dao) MockGitLabCommits(commit *ut.GitlabCommit, err error) (guard *monkey.PatchGuard) {
  164. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GitLabCommits", func(_ *Dao, _ context.Context, _ string) (*ut.GitlabCommit, error) {
  165. return commit, err
  166. })
  167. }
  168. //MockGetCoverage is
  169. func (d *Dao) MockGetCoverage(cov float64, err error) (guard *monkey.PatchGuard) {
  170. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetCoverage", func(_ *Dao, _ context.Context, _ string, _ string) (float64, error) {
  171. return cov, err
  172. })
  173. }