service_test.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/push/conf"
  9. pushmdl "go-common/app/service/main/push/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. srv *Service
  14. )
  15. func init() {
  16. dir, _ := filepath.Abs("../cmd/push-interface-test.toml")
  17. flag.Set("conf", dir)
  18. conf.Init()
  19. srv = New(conf.Conf)
  20. time.Sleep(time.Second)
  21. }
  22. func WithService(f func(s *Service)) func() {
  23. return func() {
  24. f(srv)
  25. }
  26. }
  27. func Test_Setting(t *testing.T) {
  28. Convey("setting", t, WithService(func(s *Service) {
  29. var (
  30. c = context.Background()
  31. mid = int64(91221505)
  32. )
  33. err := s.SetSetting(c, mid, pushmdl.UserSettingArchive, pushmdl.SwitchOff)
  34. So(err, ShouldBeNil)
  35. setting, err := s.Setting(c, mid)
  36. So(err, ShouldBeNil)
  37. st := make(map[int]int, len(pushmdl.Settings))
  38. for k, v := range pushmdl.Settings {
  39. st[k] = v
  40. }
  41. st[pushmdl.UserSettingArchive] = pushmdl.SwitchOff
  42. So(setting, ShouldResemble, st)
  43. }))
  44. Convey("get default setting", t, WithService(func(s *Service) {
  45. setting, err := s.Setting(context.TODO(), 8888888888888)
  46. t.Logf("setting(%+v)", pushmdl.Settings)
  47. So(err, ShouldBeNil)
  48. So(setting, ShouldResemble, pushmdl.Settings)
  49. }))
  50. }
  51. func Benchmark_Callback(b *testing.B) {
  52. Convey("callback", b, WithService(func(s *Service) {
  53. // for n := 0; n < b.N; n++ {
  54. // s.CallbackClick(context.TODO(), &pushmdl.Callback{
  55. // Type: pushmdl.CallbackTypeClick,
  56. // })
  57. // }
  58. }))
  59. }
  60. func TestServicever2build(t *testing.T) {
  61. version := "5.7.1(5730)"
  62. res := ver2build(version, pushmdl.PlatformIPhone)
  63. if res != 5730 {
  64. t.FailNow()
  65. }
  66. version = "5.7.1"
  67. res = ver2build(version, pushmdl.PlatformIPhone)
  68. if res != 5730 {
  69. t.FailNow()
  70. }
  71. version = "5.14.0"
  72. res = ver2build(version, pushmdl.PlatformAndroid)
  73. if res != 514000 {
  74. t.FailNow()
  75. }
  76. version = "5.14.0-preview"
  77. res = ver2build(version, pushmdl.PlatformAndroid)
  78. if res != 514000 {
  79. t.FailNow()
  80. }
  81. }