shellrequest_test.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "os"
  6. "testing"
  7. "go-common/app/admin/main/growup/conf"
  8. "go-common/library/net/http/blademaster"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. client *Client
  13. )
  14. func TestMain(m *testing.M) {
  15. if os.Getenv("DEPLOY_ENV") != "" {
  16. flag.Set("app_id", "mobile.studio.growup-admin")
  17. flag.Set("conf_token", "ac1fd397cbc33eb60541e8734844bdd5")
  18. flag.Set("tree_id", "13583")
  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("conf", "../../cmd/growup-admin.toml")
  27. }
  28. flag.Parse()
  29. if err := conf.Init(); err != nil {
  30. panic(err)
  31. }
  32. client = New(conf.Conf.ShellConf, blademaster.NewClient(conf.Conf.HTTPClient))
  33. os.Exit(m.Run())
  34. }
  35. func TestShellSetSign(t *testing.T) {
  36. convey.Convey("SetSign", t, func(ctx convey.C) {
  37. var (
  38. sign = "abc"
  39. o = OrderRequest{}
  40. )
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. o.SetSign(sign)
  43. ctx.Convey("No return values", func(ctx convey.C) {
  44. })
  45. })
  46. })
  47. }
  48. func TestShellSetCustomerID(t *testing.T) {
  49. convey.Convey("SetCustomerID", t, func(ctx convey.C) {
  50. var (
  51. customerID = "111"
  52. o = OrderRequest{}
  53. )
  54. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  55. o.SetCustomerID(customerID)
  56. ctx.Convey("No return values", func(ctx convey.C) {
  57. })
  58. })
  59. })
  60. }
  61. func TestShellSetSignType(t *testing.T) {
  62. convey.Convey("SetSignType", t, func(ctx convey.C) {
  63. var (
  64. signType = "111"
  65. o = OrderRequest{}
  66. )
  67. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  68. o.SetSignType(signType)
  69. ctx.Convey("No return values", func(ctx convey.C) {
  70. })
  71. })
  72. })
  73. }
  74. func TestShellIsSuccess(t *testing.T) {
  75. convey.Convey("IsSuccess", t, func(ctx convey.C) {
  76. var (
  77. o = OrderCallbackJSON{}
  78. )
  79. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  80. p1 := o.IsSuccess()
  81. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  82. ctx.So(p1, convey.ShouldNotBeNil)
  83. })
  84. })
  85. })
  86. }
  87. func TestShellIsFail(t *testing.T) {
  88. convey.Convey("IsFail", t, func(ctx convey.C) {
  89. var (
  90. o = OrderCallbackJSON{}
  91. )
  92. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  93. p1 := o.IsFail()
  94. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  95. ctx.So(p1, convey.ShouldNotBeNil)
  96. })
  97. })
  98. })
  99. }
  100. func TestShellIsCreate(t *testing.T) {
  101. convey.Convey("IsCreate", t, func(ctx convey.C) {
  102. var (
  103. o = OrderCallbackJSON{}
  104. )
  105. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  106. p1 := o.IsCreate()
  107. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  108. ctx.So(p1, convey.ShouldNotBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestShellNew(t *testing.T) {
  114. convey.Convey("New", t, func(ctx convey.C) {
  115. var (
  116. conf = &conf.ShellConfig{}
  117. httpClient = &blademaster.Client{}
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. p1 := New(conf, httpClient)
  121. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  122. ctx.So(p1, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestShellSetDebug(t *testing.T) {
  128. convey.Convey("SetDebug", t, func(ctx convey.C) {
  129. var (
  130. isDebug = true
  131. )
  132. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  133. client.SetDebug(isDebug)
  134. ctx.Convey("No return values", func(ctx convey.C) {
  135. })
  136. })
  137. })
  138. }
  139. func TestShellSendOrderRequest(t *testing.T) {
  140. convey.Convey("SendOrderRequest", t, func(ctx convey.C) {
  141. var (
  142. c = context.Background()
  143. req = &OrderRequest{
  144. CustomerID: "1001",
  145. ProductName: "test",
  146. NotifyURL: "test",
  147. Rate: "1",
  148. SignType: "test",
  149. Timestamp: "test",
  150. Sign: "test",
  151. }
  152. )
  153. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  154. res, err := client.SendOrderRequest(c, req)
  155. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  156. ctx.So(err, convey.ShouldBeNil)
  157. ctx.So(res, convey.ShouldNotBeNil)
  158. })
  159. })
  160. })
  161. }
  162. func TestShellSendCheckOrderRequest(t *testing.T) {
  163. convey.Convey("SendCheckOrderRequest", t, func(ctx convey.C) {
  164. var (
  165. c = context.Background()
  166. req = &OrderCheckRequest{}
  167. )
  168. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  169. res, err := client.SendCheckOrderRequest(c, req)
  170. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  171. ctx.So(err, convey.ShouldBeNil)
  172. ctx.So(res, convey.ShouldNotBeNil)
  173. })
  174. })
  175. })
  176. }
  177. func TestShellSendShellRequest(t *testing.T) {
  178. convey.Convey("SendShellRequest", t, func(ctx convey.C) {
  179. var (
  180. c = context.Background()
  181. url = "localhost:8080"
  182. req = interface{}(0)
  183. res = interface{}(0)
  184. )
  185. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  186. err := client.SendShellRequest(c, url, req, res)
  187. ctx.Convey("Then err should be not nil.", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldNotBeNil)
  189. })
  190. })
  191. })
  192. }