client_test.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package v1
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/infra/config/conf"
  6. "go-common/app/infra/config/model"
  7. "github.com/BurntSushi/toml"
  8. . "github.com/smartystreets/goconvey/convey"
  9. )
  10. func svr(t *testing.T) *Service {
  11. var (
  12. confPath = "../cmd/config-service-example.toml"
  13. conf *conf.Config
  14. )
  15. Convey("get apply", t, func() {
  16. _, err := toml.DecodeFile(confPath, &conf)
  17. So(err, ShouldBeNil)
  18. })
  19. return New(conf)
  20. }
  21. func TestService_CheckVersionest(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. svrName = "zjx_test"
  25. hostname = "test_host"
  26. bver = "v1.0.0"
  27. ip = "123"
  28. version = int64(-1)
  29. env = "10"
  30. token = "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc"
  31. appoint = int64(97)
  32. )
  33. svr := svr(t)
  34. rhost := &model.Host{Service: svrName, Name: hostname, BuildVersion: bver, IP: ip, ConfigVersion: version, Appoint: appoint, Customize: "test"}
  35. Convey("get tag id by name", t, func() {
  36. event, err := svr.CheckVersion(c, rhost, env, token)
  37. So(err, ShouldBeNil)
  38. So(event, ShouldNotBeEmpty)
  39. Convey("get tag id by name", func() {
  40. e := <-event
  41. So(e, ShouldNotBeEmpty)
  42. })
  43. })
  44. }
  45. func TestService_Hosts(t *testing.T) {
  46. svr := svr(t)
  47. Convey("should get hosts", t, func() {
  48. _, err := svr.Hosts(context.TODO(), "zjx_test", "10")
  49. So(err, ShouldBeNil)
  50. })
  51. }
  52. func TestService_Config(t *testing.T) {
  53. var (
  54. c = context.TODO()
  55. svrName = "zjx_test"
  56. hostname = "test_host"
  57. bver = "v1.0.0"
  58. version = int64(78)
  59. env = "10"
  60. token = "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc"
  61. )
  62. svr := svr(t)
  63. service := &model.Service{Name: svrName, BuildVersion: bver, Env: env, Token: token, Version: version, Host: hostname}
  64. Convey("should get hosts", t, func() {
  65. conf, err := svr.Config(c, service)
  66. So(err, ShouldBeNil)
  67. So(conf, ShouldNotBeEmpty)
  68. })
  69. }
  70. func TestService_Config2(t *testing.T) {
  71. var (
  72. c = context.TODO()
  73. svrName = "config_test"
  74. hostname = "test_host"
  75. bver = "shsb-docker-1"
  76. version = int64(199)
  77. env = "10"
  78. token = "qmVUPwNXnNfcSpuyqbiIBb0H4GcbSZFV"
  79. )
  80. service := &model.Service{Name: svrName, BuildVersion: bver, Env: env, Token: token, Version: version, Host: hostname}
  81. svr := svr(t)
  82. Convey("should get Config2", t, func() {
  83. conf, err := svr.Config2(c, service)
  84. So(err, ShouldBeNil)
  85. So(conf, ShouldNotBeEmpty)
  86. })
  87. }
  88. func TestService_Push(t *testing.T) {
  89. var (
  90. c = context.TODO()
  91. svrName = "zjx_test"
  92. bver = "v1.0.0"
  93. version = int64(113)
  94. env = "10"
  95. )
  96. service := &model.Service{Name: svrName, BuildVersion: bver, Version: version, Env: env}
  97. svr := svr(t)
  98. Convey("should get Config2", t, func() {
  99. err := svr.Push(c, service)
  100. So(err, ShouldBeNil)
  101. })
  102. }
  103. func TestService_SetToken(t *testing.T) {
  104. var (
  105. c = context.TODO()
  106. svrName = "zjx_test"
  107. env = "10"
  108. token = "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc"
  109. )
  110. svr := svr(t)
  111. Convey("should get Config2", t, func() {
  112. svr.SetToken(c, svrName, env, token)
  113. })
  114. }
  115. func TestService_ClearHost(t *testing.T) {
  116. var (
  117. c = context.TODO()
  118. svrName = "zjx_test"
  119. env = "10"
  120. )
  121. svr := svr(t)
  122. Convey("should clear host", t, func() {
  123. err := svr.ClearHost(c, svrName, env)
  124. So(err, ShouldBeNil)
  125. })
  126. }
  127. func TestService_VersionSuccess(t *testing.T) {
  128. var (
  129. c = context.TODO()
  130. svrName = "zjx_test"
  131. bver = "v1.0.0"
  132. env = "10"
  133. )
  134. svr := svr(t)
  135. Convey("should clear host", t, func() {
  136. vers, err := svr.VersionSuccess(c, svrName, env, bver)
  137. So(err, ShouldBeNil)
  138. So(vers, ShouldNotBeEmpty)
  139. })
  140. }
  141. func TestService_Builds(t *testing.T) {
  142. var (
  143. c = context.TODO()
  144. svrName = "zjx_test"
  145. env = "10"
  146. err error
  147. builds []string
  148. )
  149. svr := svr(t)
  150. Convey("should clear host", t, func() {
  151. builds, err = svr.Builds(c, svrName, env)
  152. So(err, ShouldBeNil)
  153. So(builds, ShouldNotBeEmpty)
  154. })
  155. }
  156. func TestService_File(t *testing.T) {
  157. var (
  158. c = context.TODO()
  159. svrName = "zjx_test"
  160. bver = "v1.0.0"
  161. env = "10"
  162. fileName = "test.toml"
  163. token = "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc"
  164. ver = int64(74)
  165. err error
  166. )
  167. service := &model.Service{Name: svrName, BuildVersion: bver, Env: env, File: fileName, Token: token, Version: ver}
  168. svr := svr(t)
  169. Convey("should clear host", t, func() {
  170. _, err = svr.File(c, service)
  171. So(err, ShouldBeNil)
  172. })
  173. }
  174. func TestService_AddConfigs(t *testing.T) {
  175. svr := svr(t)
  176. Convey("should clear host", t, func() {
  177. err := svr.AddConfigs(context.TODO(), "zjx_test", "10", "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc", "zjx", map[string]string{"aa": "bb"})
  178. So(err, ShouldBeNil)
  179. })
  180. }
  181. func TestService_UpdateConfigs(t *testing.T) {
  182. svr := svr(t)
  183. Convey("should clear host", t, func() {
  184. err := svr.UpdateConfigs(context.TODO(), "zjx_test", "10", "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc", "zjx", 491, map[string]string{"test": "test123"})
  185. So(err, ShouldBeNil)
  186. })
  187. }
  188. func TestService_CopyConfigs(t *testing.T) {
  189. svr := svr(t)
  190. Convey("should clear host", t, func() {
  191. _, err := svr.CopyConfigs(context.TODO(), "zjx_test", "10", "AXiLBa3Bww3inhfm6qx7g0zLY6WkLSZc", "zjx", "shsb-docker-1")
  192. So(err, ShouldBeNil)
  193. })
  194. }
  195. func TestService_VersionIng(t *testing.T) {
  196. svr := svr(t)
  197. Convey("should clear host", t, func() {
  198. _, err := svr.VersionIng(context.TODO(), "zjx_test1", "10")
  199. So(err, ShouldBeNil)
  200. })
  201. }