service_test.go 586 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/job/main/playlist/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. svr *Service
  13. )
  14. func init() {
  15. dir, _ := filepath.Abs("../cmd/playlist-job-test.toml")
  16. flag.Set("conf", dir)
  17. conf.Init()
  18. svr = New(conf.Conf)
  19. time.Sleep(time.Second)
  20. }
  21. func WithService(f func(s *Service)) func() {
  22. return func() {
  23. f(svr)
  24. }
  25. }
  26. func TestService_Ping(t *testing.T) {
  27. Convey("test ping", t, WithService(func(s *Service) {
  28. err := s.Ping(context.TODO())
  29. So(err, ShouldBeNil)
  30. }))
  31. }