service_test.go 605 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "path/filepath"
  6. "time"
  7. "go-common/app/interface/main/history/conf"
  8. "go-common/library/cache/redis"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. s *Service
  13. )
  14. func CleanCache() {
  15. c := context.TODO()
  16. pool := redis.NewPool(conf.Conf.Redis.Config)
  17. pool.Get(c).Do("FLUSHDB")
  18. }
  19. func WithService(f func(s *Service)) func() {
  20. return func() {
  21. Reset(func() { CleanCache() })
  22. f(s)
  23. }
  24. }
  25. func init() {
  26. dir, _ := filepath.Abs("../cmd/history-interface-test.toml")
  27. flag.Set("conf", dir)
  28. conf.Init()
  29. s = New(conf.Conf)
  30. time.Sleep(time.Second)
  31. }