dao_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/growup/conf"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func CleanMysql() {
  14. }
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "mobile.studio.growup-admin")
  18. flag.Set("conf_token", "ac1fd397cbc33eb60541e8734844bdd5")
  19. flag.Set("tree_id", "13583")
  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. flag.Set("conf", "../cmd/growup-admin.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(err)
  32. }
  33. d = New(conf.Conf)
  34. os.Exit(m.Run())
  35. }
  36. func WithMysql(f func(d *Dao)) func() {
  37. return func() {
  38. Reset(func() { CleanMysql() })
  39. f(d)
  40. }
  41. }
  42. // Exec do exec
  43. func Exec(c context.Context, sql string) (rows int64, err error) {
  44. res, err := d.rddb.Exec(c, sql)
  45. if err != nil {
  46. return
  47. }
  48. return res.RowsAffected()
  49. }