channel_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package channel
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/app-channel/conf"
  9. "go-common/app/interface/main/app-channel/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. s *Service
  14. )
  15. func WithService(f func(s *Service)) func() {
  16. return func() {
  17. f(s)
  18. }
  19. }
  20. func init() {
  21. dir, _ := filepath.Abs("../../cmd/app-channel-test.toml")
  22. flag.Set("conf", dir)
  23. conf.Init()
  24. s = New(conf.Conf)
  25. time.Sleep(time.Second)
  26. }
  27. func TestTab(t *testing.T) {
  28. Convey("get Tab data", t, WithService(func(s *Service) {
  29. res, err := s.Tab(context.TODO(), 1, 1, "", 1)
  30. So(res, ShouldNotBeEmpty)
  31. So(err, ShouldBeNil)
  32. }))
  33. }
  34. func TestSubscribeAdd(t *testing.T) {
  35. Convey("get SubscribeAdd data", t, WithService(func(s *Service) {
  36. err := s.SubscribeAdd(context.TODO(), 1, 1, time.Now())
  37. So(err, ShouldBeNil)
  38. }))
  39. }
  40. func TestSubscribeCancel(t *testing.T) {
  41. Convey("get SubscribeCancel data", t, WithService(func(s *Service) {
  42. err := s.SubscribeCancel(context.TODO(), 1, 1, time.Now())
  43. So(err, ShouldBeNil)
  44. }))
  45. }
  46. func TestSubscribeUpdate(t *testing.T) {
  47. Convey("get SubscribeUpdate data", t, WithService(func(s *Service) {
  48. err := s.SubscribeUpdate(context.TODO(), 1, "")
  49. So(err, ShouldBeNil)
  50. }))
  51. }
  52. func TestList(t *testing.T) {
  53. Convey("get List data", t, WithService(func(s *Service) {
  54. res, err := s.List(context.TODO(), 1, model.PlatIPhone, 1, 1, "", "iphone", "phone", "hans")
  55. So(err, ShouldBeNil)
  56. So(res, ShouldNotBeEmpty)
  57. }))
  58. }
  59. func TestRecommend(t *testing.T) {
  60. Convey("get Recommend data", t, WithService(func(s *Service) {
  61. res, err := s.Recommend(context.TODO(), 1, 1)
  62. So(err, ShouldBeNil)
  63. So(res, ShouldNotBeEmpty)
  64. }))
  65. }
  66. func TestSubscribe(t *testing.T) {
  67. Convey("get Subscribe data", t, WithService(func(s *Service) {
  68. res, err := s.Subscribe(context.TODO(), 1, 1)
  69. So(err, ShouldBeNil)
  70. So(res, ShouldNotBeEmpty)
  71. }))
  72. }
  73. func TestDiscover(t *testing.T) {
  74. Convey("get Discover data", t, WithService(func(s *Service) {
  75. res, err := s.Discover(context.TODO(), 1, 1, 1)
  76. So(err, ShouldBeNil)
  77. So(res, ShouldNotBeEmpty)
  78. }))
  79. }
  80. func TestCategory(t *testing.T) {
  81. Convey("get Category data", t, WithService(func(s *Service) {
  82. res, err := s.Category(context.TODO(), 1)
  83. So(err, ShouldBeNil)
  84. So(res, ShouldNotBeEmpty)
  85. }))
  86. }
  87. func TestRegionList(t *testing.T) {
  88. Convey("get RegionList data", t, WithService(func(s *Service) {
  89. _, _, _, err := s.RegionList(context.TODO(), model.PlatIPhone, 1, "iphone", "device", "hans")
  90. So(err, ShouldBeNil)
  91. }))
  92. }
  93. func TestIndex(t *testing.T) {
  94. Convey("get Index data", t, WithService(func(s *Service) {
  95. res, err := s.Index(context.TODO(), 1, 1, 1, model.PlatIPhone, "", "", "", "", 1, 1, 1, 0, 0, 0, false, time.Now())
  96. So(err, ShouldBeNil)
  97. So(res, ShouldNotBeEmpty)
  98. }))
  99. }