monkey.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package weeklyhonor
  2. import (
  3. "context"
  4. model "go-common/app/interface/main/creative/model/weeklyhonor"
  5. upgrpc "go-common/app/service/main/up/api/v1"
  6. "reflect"
  7. "github.com/bouk/monkey"
  8. )
  9. //MockHonorStat is
  10. func (d *Dao) MockHonorStat(stat *model.HonorStat, err error) (guard *monkey.PatchGuard) {
  11. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "HonorStat", func(_ *Dao, _ context.Context, _ int64, _ string) (*model.HonorStat, error) {
  12. return stat, err
  13. })
  14. }
  15. //MockSendNotify is
  16. func (d *Dao) MockSendNotify(err error) (guard *monkey.PatchGuard) {
  17. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "SendNotify", func(_ *Dao, _ context.Context, _ []int64) error {
  18. return err
  19. })
  20. }
  21. //MockLatestHonorLogs is
  22. func (d *Dao) MockLatestHonorLogs(hls []*model.HonorLog, err error) (guard *monkey.PatchGuard) {
  23. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "LatestHonorLogs", func(_ *Dao, _ context.Context, _ []int64) ([]*model.HonorLog, error) {
  24. return hls, err
  25. })
  26. }
  27. //MockClickCounts is
  28. func (d *Dao) MockClickCounts(res map[int64]int32, err error) (guard *monkey.PatchGuard) {
  29. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "ClickCounts", func(_ *Dao, _ context.Context, _ []int64) (map[int64]int32, error) {
  30. return res, err
  31. })
  32. }
  33. //MockUpCount is
  34. func (d *Dao) MockUpCount(count int, err error) (guard *monkey.PatchGuard) {
  35. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpCount", func(_ *Dao, _ context.Context, _ int64) (int, error) {
  36. return count, err
  37. })
  38. }
  39. //MockUpActivesList is
  40. func (d *Dao) MockUpActivesList(upActives []*upgrpc.UpActivity, newid int64, err error) (guard *monkey.PatchGuard) {
  41. return monkey.PatchInstanceMethod(reflect.TypeOf(d), "UpActivesList", func(_ *Dao, _ context.Context, _ int64, _ int) ([]*upgrpc.UpActivity, int64, error) {
  42. return upActives, newid, err
  43. })
  44. }