push_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package service
  2. import (
  3. . "github.com/smartystreets/goconvey/convey"
  4. "go-common/app/interface/live/push-live/model"
  5. "math/rand"
  6. "strconv"
  7. "testing"
  8. )
  9. func makeTestInitPushTask(targetID int64, uname, linkValue,
  10. roomTitle string, expireTime int) (task *model.ApPushTask) {
  11. m := &model.StartLiveMessage{
  12. TargetID: targetID,
  13. Uname: uname,
  14. LinkValue: linkValue,
  15. RoomTitle: roomTitle,
  16. ExpireTime: expireTime,
  17. }
  18. task = s.InitPushTask(m)
  19. return
  20. }
  21. func TestService_Push(t *testing.T) {
  22. initd()
  23. Convey("test push func", t, func() {
  24. // test empty mids
  25. targetID := rand.Int63n(100) + 1
  26. uname := "测试"
  27. linkValue := strconv.Itoa(rand.Intn(9999))
  28. roomTitle := "room_title"
  29. expireTime := rand.Intn(10000) + 1
  30. task := makeTestInitPushTask(targetID, uname, linkValue, roomTitle, expireTime)
  31. midMap := make(map[int][]int64)
  32. midMap[model.RelationAttention] = []int64{}
  33. total := s.Push(task, midMap)
  34. So(total, ShouldEqual, 0)
  35. })
  36. }
  37. func TestService_GetPushGroup(t *testing.T) {
  38. initd()
  39. Convey("test get group by different push type", t, func() {
  40. var (
  41. group string
  42. testGroup = "test_group"
  43. )
  44. group = s.GetPushGroup(model.RelationAttention, "")
  45. So(group, ShouldEqual, model.AttentionGroup)
  46. group = s.GetPushGroup(model.RelationSpecial, "")
  47. So(group, ShouldEqual, model.SpecialGroup)
  48. group = s.GetPushGroup(rand.Intn(9999), testGroup)
  49. So(group, ShouldEqual, testGroup)
  50. })
  51. }