service_test.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package service
  2. import (
  3. "context"
  4. "flag"
  5. "testing"
  6. "go-common/app/admin/main/aegis/conf"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. var (
  10. s *Service
  11. cntx context.Context
  12. )
  13. func init() {
  14. flag.Set("conf", "../cmd/aegis-admin.toml")
  15. flag.Parse()
  16. if err := conf.Init(); err != nil {
  17. panic(err)
  18. }
  19. s = New(conf.Conf)
  20. cntx = context.Background()
  21. }
  22. /*
  23. func TestMain(m *testing.M) {
  24. if os.Getenv("DEPLOY_ENV") != "" {
  25. flag.Set("app_id", "main.archive.aegis-admin")
  26. flag.Set("conf_token", "cad913269be022e1eb8c45a8d5408d78")
  27. flag.Set("tree_id", "60977")
  28. flag.Set("conf_version", "1")
  29. flag.Set("deploy_env", "uat")
  30. flag.Set("conf_host", "config.bilibili.co")
  31. flag.Set("conf_path", "/tmp")
  32. flag.Set("region", "sh")
  33. flag.Set("zone", "sh001")
  34. } else {
  35. flag.Set("conf", "../cmd/local.toml")
  36. }
  37. flag.Parse()
  38. if err := conf.Init(); err != nil {
  39. panic(err)
  40. }
  41. conf.Conf.AegisPub = &databus.Config{
  42. // Key: "0PvKGhAqDvsK7zitmS8t",
  43. // Secret: "0PvKGhAqDvsK7zitmS8u",
  44. // Group: "databus_test_group",
  45. // Topic: "databus_test_topic",
  46. Key: "dbe67e6a4c36f877",
  47. Secret: "8c775ea242caa367ba5c876c04576571",
  48. Group: "Test1-MainCommonArch-P",
  49. Topic: "test1",
  50. Action: "pub",
  51. Name: "databus",
  52. Proto: "tcp",
  53. // Addr: "172.16.33.158:6205",
  54. Addr: "172.18.33.50:6205",
  55. Active: 10,
  56. Idle: 5,
  57. DialTimeout: xtime.Duration(time.Second),
  58. WriteTimeout: xtime.Duration(time.Second),
  59. ReadTimeout: xtime.Duration(time.Second),
  60. IdleTimeout: xtime.Duration(time.Minute),
  61. }
  62. s = New(conf.Conf)
  63. cntx = context.Background()
  64. m.Run()
  65. os.Exit(0)
  66. }
  67. */
  68. func TestServicePing(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. )
  72. convey.Convey("Ping", t, func(ctx convey.C) {
  73. err := s.Ping(c)
  74. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  75. ctx.So(err, convey.ShouldBeNil)
  76. })
  77. })
  78. }
  79. func TestServiceClose(t *testing.T) {
  80. convey.Convey("Close", t, func(ctx convey.C) {
  81. //s.Close()
  82. //ctx.Convey("No return values", func(ctx convey.C) {
  83. //})
  84. })
  85. }