dao_test.go 701 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package dao
  2. import (
  3. "flag"
  4. "path/filepath"
  5. "sync"
  6. "time"
  7. "go-common/app/job/main/figure/conf"
  8. "go-common/library/log"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. once sync.Once
  13. d *Dao
  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 startService() {
  23. initConf()
  24. if d == nil {
  25. d = New(conf.Conf)
  26. }
  27. time.Sleep(time.Second * 2)
  28. }
  29. func CleanDB() {
  30. }
  31. func init() {
  32. dir, _ := filepath.Abs("../cmd/figure-job-test.toml")
  33. flag.Set("conf", dir)
  34. conf.Init()
  35. if d == nil {
  36. d = New(conf.Conf)
  37. }
  38. }
  39. func WithDao(f func(d *Dao)) func() {
  40. return func() {
  41. Reset(func() { CleanDB() })
  42. f(d)
  43. }
  44. }