dao_test.go 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/service/main/location/conf"
  8. "go-common/library/cache/redis"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "main.app-svr.location-service")
  17. flag.Set("conf_token", "bdc7976c3e1dbf8adeb1cdb7b1e823af")
  18. flag.Set("tree_id", "3170")
  19. flag.Set("conf_version", "docker-1")
  20. flag.Set("deploy_env", "uat")
  21. flag.Set("conf_host", "config.bilibili.co")
  22. flag.Set("conf_path", "/tmp")
  23. flag.Set("region", "sh")
  24. flag.Set("zone", "sh001")
  25. } else {
  26. flag.Set("conf", "../cmd/location-example.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. d = New(conf.Conf)
  33. m.Run()
  34. os.Exit(0)
  35. }
  36. func CleanCache() {
  37. pool := redis.NewPool(conf.Conf.Redis.Zlimit.Config)
  38. pool.Get(context.TODO()).Do("FLUSHDB")
  39. }
  40. func WithDao(f func(d *Dao)) func() {
  41. return func() {
  42. convey.Reset(func() { CleanCache() })
  43. f(d)
  44. }
  45. }