monkey.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. notice "go-common/app/service/bbq/notice-service/api/v1"
  6. "go-common/app/service/bbq/user/api"
  7. "go-common/app/service/bbq/user/internal/model"
  8. acc "go-common/app/service/main/account/api"
  9. "go-common/library/database/sql"
  10. "go-common/library/time"
  11. "reflect"
  12. "github.com/bouk/monkey"
  13. )
  14. // MockUserBase .
  15. func (d *Dao) MockUserBase(res map[int64]*api.UserBase, err error) (guard *monkey.PatchGuard) {
  16. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UserBase", func(_ *Dao, _ context.Context, _ []int64) (map[int64]*api.UserBase, error) {
  17. return res, err
  18. })
  19. }
  20. // MockPing .
  21. func (d *Dao) MockPing(err error) (guard *monkey.PatchGuard) {
  22. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "Ping", func(_ *Dao, _ context.Context) error {
  23. return err
  24. })
  25. }
  26. // MockBeginTran .
  27. func (d *Dao) MockBeginTran(p1 *xsql.Tx, err error) (guard *monkey.PatchGuard) {
  28. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "BeginTran", func(_ *Dao, _ context.Context) (*xsql.Tx, error) {
  29. return p1, err
  30. })
  31. }
  32. // MockCreateNotice .
  33. func (d *Dao) MockCreateNotice(err error) (guard *monkey.PatchGuard) {
  34. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CreateNotice", func(_ *Dao, _ context.Context, _ *notice.NoticeBase) error {
  35. return err
  36. })
  37. }
  38. // MockFilter .
  39. func (d *Dao) MockFilter(level int32, err error) (guard *monkey.PatchGuard) {
  40. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "Filter", func(_ *Dao, _ context.Context, _ string, _ string) (int32, error) {
  41. return level, err
  42. })
  43. }
  44. // MockForbidUser .
  45. func (d *Dao) MockForbidUser(err error) (guard *monkey.PatchGuard) {
  46. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "ForbidUser", func(_ *Dao, _ context.Context, _ uint64, _ uint64) error {
  47. return err
  48. })
  49. }
  50. // MockReleaseUser .
  51. func (d *Dao) MockReleaseUser(err error) (guard *monkey.PatchGuard) {
  52. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "ReleaseUser", func(_ *Dao, _ context.Context, _ uint64) error {
  53. return err
  54. })
  55. }
  56. // MockGetLocation .
  57. func (d *Dao) MockGetLocation(p1 *api.LocationItem, err error) (guard *monkey.PatchGuard) {
  58. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetLocation", func(_ *Dao, _ context.Context, _ int32) (*api.LocationItem, error) {
  59. return p1, err
  60. })
  61. }
  62. // MockGetUserBProfile .
  63. func (d *Dao) MockGetUserBProfile(res *acc.ProfileReply, err error) (guard *monkey.PatchGuard) {
  64. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetUserBProfile", func(_ *Dao, _ context.Context, _ *api.PhoneCheckReq) (*acc.ProfileReply, error) {
  65. return res, err
  66. })
  67. }
  68. // MockRawUserBase .
  69. func (d *Dao) MockRawUserBase(res map[int64]*api.UserBase, err error) (guard *monkey.PatchGuard) {
  70. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "RawUserBase", func(_ *Dao, _ context.Context, _ []int64) (map[int64]*api.UserBase, error) {
  71. return res, err
  72. })
  73. }
  74. // MockCacheUserBase .
  75. func (d *Dao) MockCacheUserBase(res map[int64]*api.UserBase, err error) (guard *monkey.PatchGuard) {
  76. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CacheUserBase", func(_ *Dao, _ context.Context, _ []int64) (map[int64]*api.UserBase, error) {
  77. return res, err
  78. })
  79. }
  80. // MockAddCacheUserBase .
  81. func (d *Dao) MockAddCacheUserBase(err error) (guard *monkey.PatchGuard) {
  82. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "AddCacheUserBase", func(_ *Dao, _ context.Context, _ map[int64]*api.UserBase) error {
  83. return err
  84. })
  85. }
  86. // MockUpdateUserField .
  87. func (d *Dao) MockUpdateUserField(num int64, err error) (guard *monkey.PatchGuard) {
  88. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateUserField", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ string, _ interface{}) (int64, error) {
  89. return num, err
  90. })
  91. }
  92. // MockAddUserBase .
  93. func (d *Dao) MockAddUserBase(num int64, err error) (guard *monkey.PatchGuard) {
  94. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "AddUserBase", func(_ *Dao, _ context.Context, _ *api.UserBase) (int64, error) {
  95. return num, err
  96. })
  97. }
  98. // MockUpdateUserBaseUname .
  99. func (d *Dao) MockUpdateUserBaseUname(num int64, err error) (guard *monkey.PatchGuard) {
  100. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateUserBaseUname", func(_ *Dao, _ context.Context, _ int64, _ string) (int64, error) {
  101. return num, err
  102. })
  103. }
  104. // MockUpdateUserBase .
  105. func (d *Dao) MockUpdateUserBase(num int64, err error) (guard *monkey.PatchGuard) {
  106. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateUserBase", func(_ *Dao, _ context.Context, _ int64, _ *api.UserBase) (int64, error) {
  107. return num, err
  108. })
  109. }
  110. // MockCheckUname .
  111. func (d *Dao) MockCheckUname(err error) (guard *monkey.PatchGuard) {
  112. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CheckUname", func(_ *Dao, _ context.Context, _ int64, _ string) error {
  113. return err
  114. })
  115. }
  116. // MockTxAddUserBlack .
  117. func (d *Dao) MockTxAddUserBlack(num int64, err error) (guard *monkey.PatchGuard) {
  118. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxAddUserBlack", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  119. return num, err
  120. })
  121. }
  122. // MockTxCancelUserBlack .
  123. func (d *Dao) MockTxCancelUserBlack(num int64, err error) (guard *monkey.PatchGuard) {
  124. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxCancelUserBlack", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  125. return num, err
  126. })
  127. }
  128. // MockFetchBlackList .
  129. func (d *Dao) MockFetchBlackList(upMid []int64, err error) (guard *monkey.PatchGuard) {
  130. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "FetchBlackList", func(_ *Dao, _ context.Context, _ int64) ([]int64, error) {
  131. return upMid, err
  132. })
  133. }
  134. // MockFetchPartBlackList .
  135. func (d *Dao) MockFetchPartBlackList(MID2IDMap map[int64]time.Time, blackMIDs []int64, err error) (guard *monkey.PatchGuard) {
  136. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "FetchPartBlackList", func(_ *Dao, _ context.Context, _ int64, _ model.CursorValue, _ int) (map[int64]time.Time, []int64, error) {
  137. return MID2IDMap, blackMIDs, err
  138. })
  139. }
  140. // MockIsBlack .
  141. func (d *Dao) MockIsBlack(MIDMap map[int64]bool) (guard *monkey.PatchGuard) {
  142. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "IsBlack", func(_ *Dao, _ context.Context, _ int64, _ []int64) map[int64]bool {
  143. return MIDMap
  144. })
  145. }
  146. // MockRawUserCard .
  147. func (d *Dao) MockRawUserCard(userCard *model.UserCard, err error) (guard *monkey.PatchGuard) {
  148. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "RawUserCard", func(_ *Dao, _ context.Context, _ int64) (*model.UserCard, error) {
  149. return userCard, err
  150. })
  151. }
  152. // MockRawUserCards .
  153. func (d *Dao) MockRawUserCards(userCards map[int64]*model.UserCard, err error) (guard *monkey.PatchGuard) {
  154. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "RawUserCards", func(_ *Dao, _ context.Context, _ []int64) (map[int64]*model.UserCard, error) {
  155. return userCards, err
  156. })
  157. }
  158. // MockRawUserAccCards .
  159. func (d *Dao) MockRawUserAccCards(res *acc.CardsReply, err error) (guard *monkey.PatchGuard) {
  160. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "RawUserAccCards", func(_ *Dao, _ context.Context, _ []int64) (*acc.CardsReply, error) {
  161. return res, err
  162. })
  163. }
  164. // MockTxAddUserFan .
  165. func (d *Dao) MockTxAddUserFan(num int64, err error) (guard *monkey.PatchGuard) {
  166. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxAddUserFan", func(_ *Dao, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  167. return num, err
  168. })
  169. }
  170. // MockTxCancelUserFan .
  171. func (d *Dao) MockTxCancelUserFan(num int64, err error) (guard *monkey.PatchGuard) {
  172. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxCancelUserFan", func(_ *Dao, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  173. return num, err
  174. })
  175. }
  176. // MockIsFan .
  177. func (d *Dao) MockIsFan(MIDMap map[int64]bool) (guard *monkey.PatchGuard) {
  178. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "IsFan", func(_ *Dao, _ context.Context, _ int64, _ []int64) map[int64]bool {
  179. return MIDMap
  180. })
  181. }
  182. // MockFetchPartFanList .
  183. func (d *Dao) MockFetchPartFanList(MID2IDMap map[int64]time.Time, followedMIDs []int64, err error) (guard *monkey.PatchGuard) {
  184. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "FetchPartFanList", func(_ *Dao, _ context.Context, _ int64, _ model.CursorValue, _ int) (map[int64]time.Time, []int64, error) {
  185. return MID2IDMap, followedMIDs, err
  186. })
  187. }
  188. // MockTxAddUserFollow .
  189. func (d *Dao) MockTxAddUserFollow(num int64, err error) (guard *monkey.PatchGuard) {
  190. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxAddUserFollow", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  191. return num, err
  192. })
  193. }
  194. // MockTxCancelUserFollow .
  195. func (d *Dao) MockTxCancelUserFollow(num int64, err error) (guard *monkey.PatchGuard) {
  196. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxCancelUserFollow", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  197. return num, err
  198. })
  199. }
  200. // MockFetchFollowList .
  201. func (d *Dao) MockFetchFollowList(upMid []int64, err error) (guard *monkey.PatchGuard) {
  202. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "FetchFollowList", func(_ *Dao, _ context.Context, _ int64) ([]int64, error) {
  203. return upMid, err
  204. })
  205. }
  206. // MockFetchPartFollowList .
  207. func (d *Dao) MockFetchPartFollowList(MID2IDMap map[int64]time.Time, followedMIDs []int64, err error) (guard *monkey.PatchGuard) {
  208. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "FetchPartFollowList", func(_ *Dao, _ context.Context, _ int64, _ model.CursorValue, _ int) (map[int64]time.Time, []int64, error) {
  209. return MID2IDMap, followedMIDs, err
  210. })
  211. }
  212. // MockIsFollow .
  213. func (d *Dao) MockIsFollow(MIDMap map[int64]bool) (guard *monkey.PatchGuard) {
  214. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "IsFollow", func(_ *Dao, _ context.Context, _ int64, _ []int64) map[int64]bool {
  215. return MIDMap
  216. })
  217. }
  218. // MockTxAddUserLike .
  219. func (d *Dao) MockTxAddUserLike(num int64, err error) (guard *monkey.PatchGuard) {
  220. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxAddUserLike", func(_ *Dao, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  221. return num, err
  222. })
  223. }
  224. // MockTxCancelUserLike .
  225. func (d *Dao) MockTxCancelUserLike(num int64, err error) (guard *monkey.PatchGuard) {
  226. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxCancelUserLike", func(_ *Dao, _ *sql.Tx, _ int64, _ int64) (int64, error) {
  227. return num, err
  228. })
  229. }
  230. // MockCheckUserLike .
  231. func (d *Dao) MockCheckUserLike(res []int64, err error) (guard *monkey.PatchGuard) {
  232. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "CheckUserLike", func(_ *Dao, _ context.Context, _ int64, _ []int64) ([]int64, error) {
  233. return res, err
  234. })
  235. }
  236. // MockGetUserLikeList .
  237. func (d *Dao) MockGetUserLikeList(likeSvs []*api.LikeSv, err error) (guard *monkey.PatchGuard) {
  238. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "GetUserLikeList", func(_ *Dao, _ context.Context, _ int64, _ bool, _ model.CursorValue, _ int) ([]*api.LikeSv, error) {
  239. return likeSvs, err
  240. })
  241. }
  242. // MockRawBatchUserStatistics .
  243. func (d *Dao) MockRawBatchUserStatistics(res map[int64]*api.UserStat, err error) (guard *monkey.PatchGuard) {
  244. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "RawBatchUserStatistics", func(_ *Dao, _ context.Context, _ []int64) (map[int64]*api.UserStat, error) {
  245. return res, err
  246. })
  247. }
  248. // MockTxIncrUserStatisticsFollow .
  249. func (d *Dao) MockTxIncrUserStatisticsFollow(num int64, err error) (guard *monkey.PatchGuard) {
  250. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxIncrUserStatisticsFollow", func(_ *Dao, _ *sql.Tx, _ int64) (int64, error) {
  251. return num, err
  252. })
  253. }
  254. // MockTxIncrUserStatisticsFan .
  255. func (d *Dao) MockTxIncrUserStatisticsFan(num int64, err error) (guard *monkey.PatchGuard) {
  256. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxIncrUserStatisticsFan", func(_ *Dao, _ *sql.Tx, _ int64) (int64, error) {
  257. return num, err
  258. })
  259. }
  260. // MockTxDecrUserStatisticsFollow .
  261. func (d *Dao) MockTxDecrUserStatisticsFollow(num int64, err error) (guard *monkey.PatchGuard) {
  262. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxDecrUserStatisticsFollow", func(_ *Dao, _ *sql.Tx, _ int64) (int64, error) {
  263. return num, err
  264. })
  265. }
  266. // MockTxDecrUserStatisticsFan .
  267. func (d *Dao) MockTxDecrUserStatisticsFan(num int64, err error) (guard *monkey.PatchGuard) {
  268. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxDecrUserStatisticsFan", func(_ *Dao, _ *sql.Tx, _ int64) (int64, error) {
  269. return num, err
  270. })
  271. }
  272. // MockTxIncrUserStatisticsField .
  273. func (d *Dao) MockTxIncrUserStatisticsField(rowsAffected int64, err error) (guard *monkey.PatchGuard) {
  274. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxIncrUserStatisticsField", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ string) (int64, error) {
  275. return rowsAffected, err
  276. })
  277. }
  278. // MockTxDescUserStatisticsField .
  279. func (d *Dao) MockTxDescUserStatisticsField(rowsAffected int64, err error) (guard *monkey.PatchGuard) {
  280. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "TxDescUserStatisticsField", func(_ *Dao, _ context.Context, _ *sql.Tx, _ int64, _ string) (int64, error) {
  281. return rowsAffected, err
  282. })
  283. }
  284. // MockUpdateUserVideoView .
  285. func (d *Dao) MockUpdateUserVideoView(err error) (guard *monkey.PatchGuard) {
  286. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpdateUserVideoView", func(_ *Dao, _ context.Context, _ int64, _ int64) error {
  287. return err
  288. })
  289. }