ranking_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/web/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var svf *Service
  12. func init() {
  13. dir, _ := filepath.Abs("../cmd/web-interface-test.toml")
  14. flag.Set("conf", dir)
  15. if err := conf.Init(); err != nil {
  16. panic(err)
  17. }
  18. if svf == nil {
  19. svf = New(conf.Conf)
  20. }
  21. time.Sleep(time.Second)
  22. }
  23. func WithService(f func(s *Service)) func() {
  24. return func() {
  25. f(svf)
  26. }
  27. }
  28. func TestService_RankingRegion1(t *testing.T) {
  29. Convey("should return without err", t, WithService(func(svf *Service) {
  30. res, err := svf.RankingRegion(context.Background(), 129, 3, 0)
  31. So(err, ShouldBeNil)
  32. So(len(res), ShouldBeGreaterThan, 0)
  33. }))
  34. }
  35. func TestService_RankingRegion2(t *testing.T) {
  36. Convey("should return without err", t, WithService(func(svf *Service) {
  37. res, err := svf.RankingRegion(context.Background(), 129, 3, 1)
  38. So(err, ShouldBeNil)
  39. So(len(res), ShouldBeGreaterThan, 0)
  40. }))
  41. }
  42. func TestService_RankingTag(t *testing.T) {
  43. rid := int16(24)
  44. tagID := int64(358)
  45. Convey("should return without err", t, WithService(func(svf *Service) {
  46. res, err := svf.RankingTag(context.Background(), rid, tagID)
  47. So(err, ShouldBeNil)
  48. So(len(res), ShouldBeGreaterThan, 0)
  49. }))
  50. }
  51. func TestService_Ranking(t *testing.T) {
  52. var (
  53. rid int16 = 23
  54. rankType = 1
  55. day = 1
  56. arcType = 1
  57. )
  58. Convey("test ranking Ranking", t, WithService(func(s *Service) {
  59. res, err := s.Ranking(context.Background(), rid, rankType, day, arcType)
  60. So(err, ShouldBeNil)
  61. So(res, ShouldNotBeNil)
  62. }))
  63. }
  64. func TestService_RankingIndex(t *testing.T) {
  65. Convey("test ranking RankingIndex", t, WithService(func(s *Service) {
  66. day := 1
  67. res, err := s.RankingIndex(context.Background(), day)
  68. So(err, ShouldBeNil)
  69. So(len(res), ShouldBeGreaterThan, 0)
  70. }))
  71. }
  72. func TestService_RankingRecommend(t *testing.T) {
  73. Convey("test ranking RankingRecommend", t, WithService(func(s *Service) {
  74. rid := 1
  75. res, err := s.RankingRecommend(context.Background(), int16(rid))
  76. So(err, ShouldBeNil)
  77. So(len(res), ShouldBeGreaterThan, 0)
  78. }))
  79. }
  80. func TestService_RegionCustom(t *testing.T) {
  81. Convey("test ranking ReginCustom", t, WithService(func(s *Service) {
  82. res, err := s.RegionCustom(context.Background())
  83. So(err, ShouldBeNil)
  84. So(res, ShouldNotBeNil)
  85. }))
  86. }