client_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package oppo
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "time"
  6. "go-common/app/service/main/push/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. auth = &Auth{Token: "7826d9a0-f192-4402-8a2c-b0dffbdd94da", Expire: 1519336387}
  11. cli = NewClient(auth, "com.bilibili.oppo.push.internal", time.Hour)
  12. )
  13. func init() {
  14. auth, _ = NewAuth("UTlf5g2bAOSQA9aCqYiFQh3X", "Ppq0B4xk73augxMJbEBSyu9m")
  15. }
  16. func Test_AuthExpire(t *testing.T) {
  17. convey.Convey("auth expire", t, func() {
  18. a := Auth{Expire: time.Now().Add(-8 * time.Hour).Unix()}
  19. if !a.IsExpired() {
  20. t.Errorf("access should be expire")
  21. }
  22. if auth.IsExpired() {
  23. t.Error("access should not be expire")
  24. }
  25. })
  26. }
  27. func Test_Message(t *testing.T) {
  28. convey.Convey("message", t, func() {
  29. params, _ := json.Marshal(map[string]string{
  30. "task_id": "123",
  31. "scheme": model.Scheme(1, "2", model.PlatformAndroid, model.UnknownBuild),
  32. })
  33. m := &Message{
  34. Title: "this is title",
  35. Content: "this is content",
  36. ActionType: ActionTypeInner,
  37. ActionParams: string(params),
  38. OfflineTTL: 3600,
  39. }
  40. res, err := cli.Message(m)
  41. convey.So(err, convey.ShouldBeNil)
  42. t.Logf("message result(%+v)", res)
  43. })
  44. }
  45. func Test_Pushs(t *testing.T) {
  46. convey.Convey("pushs", t, func() {
  47. res, err := cli.Push("5a72f82ba250c94f9f51540d", []string{"token1", "token2"})
  48. convey.So(err, convey.ShouldBeNil)
  49. t.Logf("push result(%+v)", res)
  50. })
  51. }
  52. func Test_PushOne(t *testing.T) {
  53. convey.Convey("push one", t, func() {
  54. params, _ := json.Marshal(map[string]string{
  55. "task_id": "123",
  56. "scheme": model.Scheme(1, "2", model.PlatformAndroid, model.UnknownBuild),
  57. })
  58. m := &Message{
  59. Title: "this is title",
  60. Content: "this is content",
  61. ActionType: ActionTypeInner,
  62. ActionParams: string(params),
  63. OfflineTTL: 3600,
  64. // CallbackURL: oppo.CallbackURL(1, 123),
  65. }
  66. res, err := cli.PushOne(m, "") // baab653406d187af12daa9980c87f4e5
  67. convey.So(err, convey.ShouldBeNil)
  68. t.Logf("pushOne result(%+v)", res)
  69. })
  70. }