dao_test.go 997 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package dao
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "go-common/app/admin/main/reply/conf"
  7. "go-common/library/conf/env"
  8. _ "github.com/go-sql-driver/mysql"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. _d *Dao
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.community.reply-admin")
  18. flag.Set("conf_token", "7c141ae4ff3f31aade1c51556fd11e8a")
  19. flag.Set("tree_id", "2124")
  20. flag.Set("conf_version", "docker-1")
  21. flag.Set("deploy_env", "uat")
  22. flag.Set("conf_host", "config.bilibili.co")
  23. flag.Set("conf_path", "/tmp")
  24. flag.Set("region", "sh")
  25. flag.Set("zone", "sh001")
  26. } else {
  27. env.DeployEnv = "uat"
  28. env.Zone = "sh001"
  29. flag.Set("conf", "../cmd/reply-admin-test.toml")
  30. }
  31. flag.Parse()
  32. if err := conf.Init(); err != nil {
  33. panic(err)
  34. }
  35. _d = New(conf.Conf)
  36. d = _d
  37. m.Run()
  38. os.Exit(0)
  39. }
  40. func CleanCache() {
  41. }
  42. func WithDao(f func(d *Dao)) func() {
  43. return func() {
  44. Reset(func() { CleanCache() })
  45. f(_d)
  46. }
  47. }