dao_test.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "go-common/app/service/main/push/conf"
  9. "go-common/app/service/main/push/model"
  10. "go-common/library/cache/redis"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var d *Dao
  14. func init() {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.web-svr.push-service")
  17. flag.Set("conf_token", "668329d872842a0079691e868e0fa12d")
  18. flag.Set("tree_id", "35083")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. dir, _ := filepath.Abs("../cmd/push-service-test.toml")
  27. flag.Set("conf", dir)
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. }
  35. func WithDao(f func(d *Dao)) func() {
  36. return func() {
  37. Reset(func() { CleanCache() })
  38. f(d)
  39. }
  40. }
  41. func CleanCache() {
  42. c := context.TODO()
  43. redisPool := redis.NewPool(conf.Conf.Redis.Config)
  44. redisPool.Get(c).Do("FLUSHDB")
  45. }
  46. func Test_MiInvalidTokens(t *testing.T) {
  47. Convey("fetch mi invalid tokens", t, WithDao(func(d *Dao) {
  48. // 用的时候打开,消息消费完了就没了
  49. // err := d.DelInvalidMiReports(context.TODO())
  50. // So(err, ShouldBeNil)
  51. }))
  52. }
  53. func Test_buildAPNS(t *testing.T) {
  54. Convey("build apns", t, func() {
  55. info := &model.PushInfo{
  56. TaskID: model.TempTaskID(),
  57. APPID: 1,
  58. Title: model.DefaultMessageTitle,
  59. Summary: "bilibili",
  60. LinkType: 8,
  61. }
  62. item := &model.PushItem{
  63. Platform: 2,
  64. Token: "sdfsdfewfsadfsdfsdf",
  65. Mid: 888,
  66. }
  67. apns := buildAPNS(info, item)
  68. t.Logf("apns(%+v)", apns)
  69. })
  70. }
  71. func Test_RefreshAuth(t *testing.T) {
  72. Convey("ping redis", t, WithDao(func(d *Dao) {
  73. err := d.Ping(context.Background())
  74. So(err, ShouldBeNil)
  75. }))
  76. }