start_live_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package service
  2. import (
  3. "context"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "go-common/app/interface/live/push-live/model"
  6. "math/rand"
  7. "strconv"
  8. "testing"
  9. )
  10. func TestService_InitPushTask(t *testing.T) {
  11. initd()
  12. Convey("should return init struct", t, func() {
  13. targetID = rand.Int63n(100) + 1
  14. uname := "测试"
  15. linkValue := strconv.Itoa(rand.Intn(9999))
  16. roomTitle := "room_title"
  17. expireTime := rand.Intn(10000) + 1
  18. task := makeTestInitPushTask(targetID, uname, linkValue, roomTitle, expireTime)
  19. So(task.TargetID, ShouldResemble, targetID)
  20. So(task.AlertTitle, ShouldResemble, uname)
  21. So(task.AlertBody, ShouldResemble, roomTitle)
  22. So(task.ExpireTime, ShouldResemble, expireTime)
  23. So(task.LinkValue, ShouldResemble, linkValue)
  24. })
  25. }
  26. func TestDao_GetSourceByTypes(t *testing.T) {
  27. initd()
  28. Convey("Get mid_source by different types", t, func() {
  29. types := []string{model.StrategySwitch, model.StrategyFans, model.StrategySpecial, model.StrategySwitchSpecial}
  30. length := len(types)
  31. currentX := rand.Intn(length)
  32. currentY := rand.Intn(length)
  33. var currentTypes []string
  34. if currentX >= currentY {
  35. currentTypes = types[currentY:currentX]
  36. } else {
  37. currentTypes = types[currentX:currentY]
  38. }
  39. midSource := s.getSourceByTypes(currentTypes)
  40. So(midSource, ShouldBeGreaterThanOrEqualTo, 0)
  41. So(midSource, ShouldBeLessThanOrEqualTo, 15)
  42. })
  43. }
  44. func TestService_GetFansBySwitch(t *testing.T) {
  45. initd()
  46. Convey("should find some fans id by given target id", t, func() {
  47. targetID = 27515316
  48. fans, fansSP, err := s.GetFansBySwitch(context.Background(), targetID)
  49. So(len(fans), ShouldBeGreaterThan, 0)
  50. So(len(fansSP), ShouldBeGreaterThan, 0)
  51. So(err, ShouldBeNil)
  52. })
  53. }
  54. func TestService_GetFansBySwitchAndSpecial(t *testing.T) {
  55. initd()
  56. Convey("should find some fans id by given target id", t, func() {
  57. targetID = 27515316
  58. fans, fansSP, err := s.GetFansBySwitchAndSpecial(context.Background(), targetID)
  59. So(len(fans), ShouldEqual, 0)
  60. So(len(fansSP), ShouldBeGreaterThan, 0)
  61. So(err, ShouldBeNil)
  62. })
  63. }
  64. func TestService_GetMids(t *testing.T) {
  65. initd()
  66. Convey("should find some fans id by given target id", t, func() {
  67. targetID = 27515316
  68. uname := "测试"
  69. linkValue := strconv.Itoa(rand.Intn(9999))
  70. roomTitle := "room_title"
  71. expireTime := rand.Intn(10000) + 1
  72. task := makeTestInitPushTask(targetID, uname, linkValue, roomTitle, expireTime)
  73. types := []string{"Switch", "Special"}
  74. s.pushTypes = types
  75. midMap := s.GetMids(context.Background(), task)
  76. for _, list := range midMap {
  77. So(len(list), ShouldBeGreaterThan, 0)
  78. }
  79. })
  80. }