ut_report_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/apm/dao"
  5. "reflect"
  6. "testing"
  7. "github.com/bouk/monkey"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestServiceWechatReport(t *testing.T) {
  11. convey.Convey("WechatReport", t, func(ctx convey.C) {
  12. var (
  13. c = context.Background()
  14. mrid = int64(10760)
  15. cid = "8d2f1b49661c7089e2b595eafff326033a138c23"
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. guard := monkey.PatchInstanceMethod(reflect.TypeOf(svr.dao), "SendWechatToGroup", func(_ *dao.Dao, _ context.Context, _ string, _ string) error {
  19. return nil
  20. })
  21. defer guard.Unpatch()
  22. err := svr.WechatReport(c, mrid, cid, "xxx", "master")
  23. ctx.Convey("Than err should be nil", func(ctx convey.C) {
  24. ctx.So(err, convey.ShouldBeNil)
  25. })
  26. })
  27. })
  28. }
  29. func TestServiceRankWechatReport(t *testing.T) {
  30. convey.Convey("RankWechatReport", t, func(ctx convey.C) {
  31. c := context.Background()
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. guard := monkey.PatchInstanceMethod(reflect.TypeOf(svr.dao), "SendWechatToGroup", func(_ *dao.Dao, _ context.Context, _ string, _ string) error {
  34. return nil
  35. })
  36. defer guard.Unpatch()
  37. err := svr.RankWechatReport(c)
  38. ctx.Convey("Then err should be nil", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestServiceSummaryWechatReport(t *testing.T) {
  45. convey.Convey("SummaryWechatReport", t, func(ctx convey.C) {
  46. var (
  47. c = context.Background()
  48. )
  49. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  50. guard := monkey.PatchInstanceMethod(reflect.TypeOf(svr.dao), "SendWechatToGroup", func(_ *dao.Dao, _ context.Context, _ string, _ string) error {
  51. return nil
  52. })
  53. defer guard.Unpatch()
  54. svr.dao.SetAppCovCache(c)
  55. err := svr.SummaryWechatReport(c)
  56. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  57. // t.Logf("\n%s", msg)
  58. ctx.So(err, convey.ShouldBeNil)
  59. })
  60. })
  61. })
  62. }