dao_test.go 1011 B

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