mail_api_client_test.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package client
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/netutil/breaker"
  8. xtime "go-common/library/time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. var cl *Client
  12. func TestNewClient(t *testing.T) {
  13. var client = bm.NewClient(&bm.ClientConfig{
  14. App: &bm.App{
  15. Key: "53e2fa226f5ad348",
  16. Secret: "3cf6bd1b0ff671021da5f424fea4b04a",
  17. },
  18. Dial: xtime.Duration(time.Second),
  19. Timeout: xtime.Duration(time.Second),
  20. KeepAlive: xtime.Duration(time.Second),
  21. Breaker: &breaker.Config{
  22. Window: 10 * xtime.Duration(time.Second),
  23. Sleep: 50 * xtime.Duration(time.Millisecond),
  24. Bucket: 10,
  25. Ratio: 0.5,
  26. Request: 100,
  27. },
  28. },
  29. )
  30. convey.Convey("NewEleClient", t, func() {
  31. cl = NewClient(client)
  32. convey.So(cl, convey.ShouldNotBeNil)
  33. })
  34. convey.Convey("Get", t, func() {
  35. err := cl.Get(context.TODO(), "http://api.bilibili.co/x/internal/vip/user/info", nil, nil)
  36. convey.So(err, convey.ShouldBeNil)
  37. })
  38. convey.Convey("Post", t, func() {
  39. err := cl.Post(context.TODO(), "http://api.bilibili.co/x/internal/vip/order/create", nil, nil)
  40. convey.So(err, convey.ShouldBeNil)
  41. })
  42. }
  43. func TestClientNewClient(t *testing.T) {
  44. convey.Convey("NewClient", t, func(convCtx convey.C) {
  45. var (
  46. client = &bm.Client{}
  47. )
  48. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  49. p1 := NewClient(client)
  50. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  51. convCtx.So(p1, convey.ShouldNotBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestClientNewRequest(t *testing.T) {
  57. convey.Convey("NewRequest", t, func(convCtx convey.C) {
  58. var (
  59. method = ""
  60. uri = ""
  61. params = interface{}(0)
  62. client = &bm.Client{}
  63. )
  64. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  65. p1 := NewClient(client)
  66. req, err := p1.NewRequest(method, uri, params)
  67. convCtx.Convey("Then err should be nil.req should not be nil.", func(convCtx convey.C) {
  68. convCtx.So(err, convey.ShouldBeNil)
  69. convCtx.So(req, convey.ShouldNotBeNil)
  70. })
  71. })
  72. })
  73. }