service_test.go 764 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "path/filepath"
  7. "testing"
  8. "go-common/app/job/main/reply/conf"
  9. _ "github.com/go-sql-driver/mysql"
  10. . "github.com/smartystreets/goconvey/convey"
  11. )
  12. var (
  13. ser *Service
  14. )
  15. func CleanCache() {
  16. }
  17. func TestMain(m *testing.M) {
  18. dir, _ := filepath.Abs("../cmd/reply-job-test.toml")
  19. flag.Set("conf", dir)
  20. err := conf.Init()
  21. if err != nil {
  22. panic("conf init err:" + err.Error())
  23. }
  24. ser = New(conf.Conf)
  25. m.Run()
  26. os.Exit(0)
  27. }
  28. func WithService(f func(ser *Service)) func() {
  29. return func() {
  30. Reset(func() { CleanCache() })
  31. f(ser)
  32. }
  33. }
  34. func TestClose(t *testing.T) {
  35. err := ser.Close()
  36. So(err, ShouldBeNil)
  37. }
  38. func TestPing(t *testing.T) {
  39. err := ser.Ping(context.Background())
  40. So(err, ShouldBeNil)
  41. }