resource_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package global
  2. import (
  3. "flag"
  4. "os"
  5. "testing"
  6. "go-common/app/service/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-service")
  12. flag.Set("conf_token", "5f1660060bb011e8865c66d44b23cda7")
  13. flag.Set("tree_id", "15572")
  14. flag.Set("conf_version", "docker-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-service.toml")
  22. }
  23. if os.Getenv("UT_LOCAL_TEST") != "" {
  24. flag.Set("conf", "../../cmd/up-service.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 TestGlobalGetArcClient(t *testing.T) {
  34. convey.Convey("GetArcClient", t, func(convCtx convey.C) {
  35. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  36. p1 := GetArcClient()
  37. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  38. convCtx.So(p1, convey.ShouldNotBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestGlobalGetAccClient(t *testing.T) {
  44. convey.Convey("GetAccClient", t, func(convCtx convey.C) {
  45. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  46. p1 := GetAccClient()
  47. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  48. convCtx.So(p1, convey.ShouldNotBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestGlobalGetWorker(t *testing.T) {
  54. convey.Convey("GetWorker", t, func(convCtx convey.C) {
  55. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  56. p1 := GetWorker()
  57. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  58. convCtx.So(p1, convey.ShouldNotBeNil)
  59. })
  60. })
  61. })
  62. }
  63. func TestGlobalGetUpCrmDB(t *testing.T) {
  64. convey.Convey("GetUpCrmDB", t, func(convCtx convey.C) {
  65. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  66. p1 := GetUpCrmDB()
  67. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  68. convCtx.So(p1, convey.ShouldNotBeNil)
  69. })
  70. })
  71. })
  72. }
  73. func TestGlobalInit(t *testing.T) {
  74. convey.Convey("Init", t, func(convCtx convey.C) {
  75. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  76. Init(conf.Conf)
  77. convCtx.Convey("No return values", func(convCtx convey.C) {
  78. })
  79. })
  80. })
  81. }
  82. func TestGlobalClose(t *testing.T) {
  83. convey.Convey("Close", t, func(convCtx convey.C) {
  84. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  85. Close()
  86. convCtx.Convey("No return values", func(convCtx convey.C) {
  87. })
  88. })
  89. })
  90. }