service_test.go 742 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package history
  2. import (
  3. "flag"
  4. "path/filepath"
  5. "testing"
  6. "time"
  7. "go-common/app/interface/main/tv/conf"
  8. "context"
  9. "encoding/json"
  10. "fmt"
  11. . "github.com/smartystreets/goconvey/convey"
  12. )
  13. var (
  14. srv *Service
  15. )
  16. func init() {
  17. dir, _ := filepath.Abs("../../cmd/tv-interface.toml")
  18. flag.Set("conf", dir)
  19. conf.Init()
  20. srv = New(conf.Conf)
  21. time.Sleep(time.Second)
  22. }
  23. func WithService(f func(s *Service)) func() {
  24. return func() {
  25. Reset(func() {})
  26. f(srv)
  27. }
  28. }
  29. func TestService_GetHistory(t *testing.T) {
  30. Convey("TestService_GetHistory", t, WithService(func(s *Service) {
  31. cont, err := s.GetHistory(context.Background(), int64(27515401))
  32. So(err, ShouldBeNil)
  33. data, _ := json.Marshal(cont)
  34. fmt.Println(string(data))
  35. }))
  36. }