service_test.go 685 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package job
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/interface/main/web-show/conf"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var svf *Service
  12. func init() {
  13. dir, _ := filepath.Abs("../../cmd/web-show-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_Jobs(t *testing.T) {
  29. Convey("should return without err", t, WithService(func(svf *Service) {
  30. res := svf.Jobs(context.TODO())
  31. So(res, ShouldNotBeNil)
  32. Printf("%+v", res)
  33. }))
  34. }