http_test.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package block
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestBlockSendSysMsg(t *testing.T) {
  9. convey.Convey("SendSysMsg", t, func(convCtx convey.C) {
  10. var (
  11. c = context.Background()
  12. code = ""
  13. mids = []int64{}
  14. title = ""
  15. content = ""
  16. remoteIP = ""
  17. )
  18. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  19. defer gock.OffAll()
  20. httpMock("POST", d.conf.BlockProperty.MSGURL).Reply(200).JSON(`{"code":0,"data":{"status":1,"remark":"test"}}`)
  21. err := d.SendSysMsg(c, code, mids, title, content, remoteIP)
  22. //println("err==",err)
  23. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  24. convCtx.So(err, convey.ShouldBeNil)
  25. })
  26. })
  27. convCtx.Convey("When everything goes negative", func(convCtx convey.C) {
  28. defer gock.OffAll()
  29. httpMock("POST", d.conf.BlockProperty.MSGURL).Reply(200).JSON(`{"code":500,"data":{"status":1,"remark":"test"}}`)
  30. //d.httpClient.SetTransport(gock.DefaultTransport)
  31. err := d.SendSysMsg(c, code, mids, title, content, remoteIP)
  32. convCtx.Convey("Then err should not be nil.", func(convCtx convey.C) {
  33. convCtx.So(err, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestBlockmidsToParam(t *testing.T) {
  39. convey.Convey("midsToParam", t, func(convCtx convey.C) {
  40. var (
  41. mids = []int64{}
  42. )
  43. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  44. str := midsToParam(mids)
  45. convCtx.Convey("Then str should not be nil.", func(convCtx convey.C) {
  46. convCtx.So(str, convey.ShouldNotBeNil)
  47. })
  48. })
  49. })
  50. }