service_test.go 807 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package service
  2. import (
  3. "flag"
  4. "go-common/app/job/main/figure/conf"
  5. "go-common/library/log"
  6. "path/filepath"
  7. "sync"
  8. "time"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. once sync.Once
  13. s *Service
  14. )
  15. func initConf() {
  16. if err := conf.Init(); err != nil {
  17. panic(err)
  18. }
  19. log.Init(conf.Conf.Log)
  20. defer log.Close()
  21. }
  22. func init() {
  23. var (
  24. err error
  25. )
  26. dir, _ := filepath.Abs("../cmd/figure-job-test.toml")
  27. flag.Set("conf", dir)
  28. if err = conf.Init(); err != nil {
  29. panic(err)
  30. }
  31. if s == nil {
  32. s = New(conf.Conf)
  33. }
  34. time.Sleep(time.Second)
  35. }
  36. func startService() {
  37. initConf()
  38. if s == nil {
  39. s = New(conf.Conf)
  40. }
  41. time.Sleep(time.Second * 2)
  42. }
  43. func CleanCache() {
  44. }
  45. func WithService(f func(s *Service)) func() {
  46. return func() {
  47. Reset(func() { CleanCache() })
  48. f(s)
  49. }
  50. }