dao_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/macross/conf"
  8. "go-common/library/database/sql"
  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.macross")
  17. flag.Set("conf_token", "5cc0121bad1156f7eb0335fbb44ce0ff")
  18. flag.Set("tree_id", "6798")
  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/macross-admin-test.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 WithReopenDB(f func(d *Dao)) func() {
  37. return func() {
  38. convey.Reset(func() {
  39. d.db = sql.NewMySQL(d.c.DB.Macross)
  40. })
  41. f(d)
  42. }
  43. }
  44. func TestDaoPing(t *testing.T) {
  45. convey.Convey("Ping", t, func(ctx convey.C) {
  46. err := d.Ping(context.TODO())
  47. ctx.Convey("Err should be nil", func() {
  48. ctx.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. }