player_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/player/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var svf *Service
  12. func WithService(f func(s *Service)) func() {
  13. return func() {
  14. dir, _ := filepath.Abs("../cmd/player-test.toml")
  15. flag.Set("conf", dir)
  16. conf.Init()
  17. if svf == nil {
  18. svf = New(conf.Conf)
  19. }
  20. time.Sleep(2 * time.Second)
  21. f(svf)
  22. }
  23. }
  24. func TestMidCrc(t *testing.T) {
  25. expects := map[int64]string{
  26. 8167601: "2425c296",
  27. 123456: "0972d361",
  28. }
  29. for mid, crc := range expects {
  30. if midCrc(mid) != crc {
  31. t.Errorf("crc %v expect %s got %s", mid, crc, midCrc(mid))
  32. }
  33. }
  34. }
  35. func TestService_Carousel(t *testing.T) {
  36. Convey("carousel len should > 0", t, WithService(func(svf *Service) {
  37. carousel, err := svf.Carousel(context.Background())
  38. So(err, ShouldBeNil)
  39. So(len(carousel), ShouldBeGreaterThan, 0)
  40. }))
  41. }
  42. func TestService_Player(t *testing.T) {
  43. Convey("player should return without err", t, WithService(func(svf *Service) {
  44. player, err := svf.Player(context.Background(), 0, 10097666, 10108404, "127.0.0.1", "", time.Now())
  45. So(err, ShouldBeNil)
  46. So(len(player), ShouldBeGreaterThan, 0)
  47. }))
  48. Convey("player should return without err", t, WithService(func(svf *Service) {
  49. player, err := svf.Player(context.Background(), 0, 10010666, 10108404, "127.0.0.1", "", time.Now())
  50. So(err, ShouldBeNil)
  51. So(len(player), ShouldBeGreaterThan, 0)
  52. }))
  53. }