service_test.go 853 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "testing"
  7. "time"
  8. "go-common/app/job/main/push/conf"
  9. pushmdl "go-common/app/service/main/push/model"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var srv *Service
  13. func init() {
  14. dir, _ := filepath.Abs("../cmd/push-job-test.toml")
  15. flag.Set("conf", dir)
  16. conf.Init()
  17. srv = New(conf.Conf)
  18. time.Sleep(time.Second)
  19. }
  20. func WithService(f func(s *Service)) func() {
  21. return func() {
  22. f(srv)
  23. }
  24. }
  25. func Test_Ping(t *testing.T) {
  26. Convey("ping", t, WithService(func(s *Service) {
  27. err := s.Ping(context.TODO())
  28. So(err, ShouldBeNil)
  29. }))
  30. }
  31. func Test_TxCond(t *testing.T) {
  32. Convey("query conditon by tx", t, WithService(func(s *Service) {
  33. cond, err := s.txCond(pushmdl.DpCondStatusPrepared, pushmdl.DpCondStatusSubmitting)
  34. So(err, ShouldBeNil)
  35. t.Logf("cond(%+v)", cond)
  36. }))
  37. }