server_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package gorpc
  2. import (
  3. "context"
  4. "testing"
  5. pushsrv "go-common/app/service/main/push/api/gorpc"
  6. "go-common/app/service/main/push/model"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. // _noArg = &struct{}{}
  11. // _noRes = &struct{}{}
  12. ctx = context.TODO()
  13. )
  14. func WithRPC(f func(client *pushsrv.Service)) func() {
  15. return func() {
  16. client := pushsrv.New(nil)
  17. f(client)
  18. }
  19. }
  20. func Test_AddReport(t *testing.T) {
  21. Convey("AddReport", t, WithRPC(func(client *pushsrv.Service) {
  22. arg := &model.ArgReport{
  23. APPID: 1,
  24. PlatformID: 1,
  25. Mid: 1,
  26. Buvid: "b",
  27. DeviceToken: "d",
  28. Build: 8080,
  29. TimeZone: 8,
  30. NotifySwitch: 1,
  31. }
  32. err := client.AddReport(ctx, arg)
  33. So(err, ShouldBeNil)
  34. }))
  35. }
  36. func Test_Setting(t *testing.T) {
  37. Convey("get setting", t, WithRPC(func(client *pushsrv.Service) {
  38. arg := &model.ArgMid{Mid: 88888888}
  39. res, err := client.Setting(ctx, arg)
  40. So(err, ShouldBeNil)
  41. t.Logf("setting(%v)", res)
  42. }))
  43. Convey("set setting", t, WithRPC(func(client *pushsrv.Service) {
  44. arg := &model.ArgSetting{Mid: 999999999, Type: model.UserSettingArchive, Value: model.SwitchOff}
  45. err := client.SetSetting(ctx, arg)
  46. So(err, ShouldBeNil)
  47. argMid := &model.ArgMid{Mid: 999999999}
  48. res, err := client.Setting(ctx, argMid)
  49. So(err, ShouldBeNil)
  50. t.Logf("setting(%v)", res)
  51. }))
  52. }
  53. func TestAddUserReportCache(t *testing.T) {
  54. Convey("AddUserReportCache", t, WithRPC(func(client *pushsrv.Service) {
  55. arg := &model.ArgUserReports{Mid: 123456, Reports: []*model.Report{{
  56. APPID: 1,
  57. PlatformID: 1,
  58. Mid: 123456,
  59. DeviceToken: "dtrpc",
  60. }}}
  61. err := client.AddUserReportCache(context.Background(), arg)
  62. So(err, ShouldBeNil)
  63. }))
  64. }
  65. func TestAddTokensCache(t *testing.T) {
  66. Convey("AddTokensCache", t, WithRPC(func(client *pushsrv.Service) {
  67. arg := &model.ArgReports{Reports: []*model.Report{{
  68. APPID: 1,
  69. PlatformID: 1,
  70. Mid: 123456,
  71. DeviceToken: "dtrpc",
  72. }, {
  73. APPID: 1,
  74. PlatformID: 1,
  75. Mid: 123456,
  76. DeviceToken: "dtrpc2",
  77. }}}
  78. err := client.AddTokensCache(context.Background(), arg)
  79. So(err, ShouldBeNil)
  80. }))
  81. }