mids_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. "go-common/app/interface/live/push-live/dao"
  6. "go-common/app/interface/live/push-live/model"
  7. "go-common/library/cache/redis"
  8. "math/rand"
  9. )
  10. func TestService_MidFilter(t *testing.T) {
  11. initd()
  12. Convey("test mid filter", t, func() {
  13. var (
  14. total int
  15. midList map[int64]bool
  16. business int
  17. resMids []int64
  18. task *model.ApPushTask
  19. err error
  20. conn redis.Conn
  21. )
  22. business = rand.Intn(99) + 1 // should through all filters
  23. // init mids input
  24. total = 10
  25. midList = make(map[int64]bool, total)
  26. for i := 0; i < total; i++ {
  27. mid := rand.Int63()
  28. midList[mid] = true
  29. }
  30. // init task
  31. task = &model.ApPushTask{
  32. LinkValue: "test",
  33. }
  34. // do mid filter
  35. resMids = s.midFilter(midList, business, task)
  36. So(len(resMids), ShouldEqual, total)
  37. // clean
  38. conn, err = redis.Dial(s.c.Redis.PushInterval.Proto, s.c.Redis.PushInterval.Addr, s.dao.RedisOption()...)
  39. So(err, ShouldBeNil)
  40. for mid := range midList {
  41. keys := []string{
  42. dao.GetDailyLimitKey(mid),
  43. dao.GetIntervalKey(mid),
  44. }
  45. for _, key := range keys {
  46. conn.Do("DEL", key)
  47. }
  48. }
  49. })
  50. }