dao_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package global
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "go-common/app/admin/main/up/conf"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestMain(m *testing.M) {
  10. if os.Getenv("DEPLOY_ENV") != "" {
  11. flag.Set("app_id", "main.archive.up-admin")
  12. flag.Set("conf_token", "930697bb7def4df0713ef8080596b863")
  13. flag.Set("tree_id", "36438")
  14. flag.Set("conf_version", "1")
  15. flag.Set("deploy_env", "uat")
  16. flag.Set("conf_host", "config.bilibili.co")
  17. flag.Set("conf_path", "/tmp")
  18. flag.Set("region", "sh")
  19. flag.Set("zone", "sh001")
  20. } else {
  21. flag.Set("conf", "../../cmd/up-admin.toml")
  22. }
  23. if os.Getenv("UT_LOCAL_TEST") != "" {
  24. flag.Set("conf", "../../cmd/up-admin.toml")
  25. }
  26. flag.Parse()
  27. if err := conf.Init(); err != nil {
  28. panic(err)
  29. }
  30. Init(conf.Conf)
  31. os.Exit(m.Run())
  32. }
  33. func TestGlobalGetAccClient(t *testing.T) {
  34. convey.Convey("GetAccClient", t, func(ctx convey.C) {
  35. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  36. p1 := GetAccClient()
  37. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  38. ctx.So(p1, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestGlobalInit(t *testing.T) {
  44. convey.Convey("Init", t, func(ctx convey.C) {
  45. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  46. Init(conf.Conf)
  47. ctx.Convey("No return values", func(ctx convey.C) {
  48. })
  49. })
  50. })
  51. }