dao_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package mysql
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "os"
  7. "testing"
  8. "go-common/app/admin/main/aegis/conf"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. d *Dao
  13. cntx context.Context
  14. )
  15. func TestMain(m *testing.M) {
  16. if os.Getenv("DEPLOY_ENV") != "" {
  17. flag.Set("app_id", "main.archive.aegis-admin")
  18. flag.Set("conf_token", "cad913269be022e1eb8c45a8d5408d78")
  19. flag.Set("tree_id", "60977")
  20. flag.Set("conf_version", "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/aegis-admin.toml")
  28. }
  29. flag.Parse()
  30. if err := conf.Init(); err != nil {
  31. panic(fmt.Sprintf("conf.Init() error(%v)", err))
  32. }
  33. d = New(conf.Conf)
  34. cntx = context.TODO()
  35. os.Exit(m.Run())
  36. }
  37. func TestMysqlPing(t *testing.T) {
  38. convey.Convey("Ping", t, func(ctx convey.C) {
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. err := d.Ping(cntx)
  41. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. })
  44. })
  45. })
  46. }