dao_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/service/main/identify/conf"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. var (
  11. d *Dao
  12. )
  13. func TestMain(m *testing.M) {
  14. if os.Getenv("DEPLOY_ENV") != "" {
  15. flag.Set("app_id", "main.account.identify-service")
  16. flag.Set("conf_appid", "identify-service")
  17. flag.Set("conf_token", "ed882ffb3c5f9ec3f4a28691a2ac3d84")
  18. flag.Set("tree_id", "11172")
  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("app_id", "main.account.identify-service")
  27. flag.Set("conf_appid", "identify-service")
  28. flag.Set("conf_token", "15fd302391c22077da13643e11d8bab6")
  29. flag.Set("tree_id", "11172")
  30. flag.Set("conf_version", "server-1")
  31. flag.Set("deploy_env", "dev")
  32. flag.Set("conf_env", "dev")
  33. flag.Set("conf_host", "config.bilibili.co")
  34. flag.Set("conf_path", "/tmp")
  35. flag.Set("region", "sh")
  36. flag.Set("zone", "sh001")
  37. }
  38. flag.Parse()
  39. if err := conf.Init(); err != nil {
  40. panic(err)
  41. }
  42. d = New(conf.Conf)
  43. m.Run()
  44. os.Exit(0)
  45. }
  46. func TestDao_Ping(t *testing.T) {
  47. convey.Convey("dao ping", t, func(ctx convey.C) {
  48. err := d.Ping(context.Background())
  49. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. })
  53. }
  54. func TestDao_pingMC(t *testing.T) {
  55. convey.Convey("dao ping", t, func(ctx convey.C) {
  56. err := d.pingMC(context.Background())
  57. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. })
  60. })
  61. }