http_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. gock "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestDaoOpenCode(t *testing.T) {
  9. var (
  10. c = context.TODO()
  11. mid = int64(0)
  12. batchCodeID = int64(0)
  13. unit = int32(0)
  14. remark = ""
  15. code = ""
  16. )
  17. convey.Convey("OpenCode", t, func(ctx convey.C) {
  18. defer gock.OffAll()
  19. httpMock("POST", _openCode).Reply(200).JSON(`{"code":0}`)
  20. data, err := d.OpenCode(c, mid, batchCodeID, unit, remark, code)
  21. ctx.Convey("Error should be nil", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldBeNil)
  23. })
  24. ctx.Convey("data should not be nil", func(ctx convey.C) {
  25. ctx.So(data, convey.ShouldNotBeNil)
  26. })
  27. })
  28. }
  29. func TestDaoGetOpenInfo(t *testing.T) {
  30. var (
  31. c = context.TODO()
  32. code = ""
  33. )
  34. convey.Convey("GetOpenInfo", t, func(ctx convey.C) {
  35. defer gock.OffAll()
  36. httpMock("GET", _openCode).Reply(200).JSON(`{"code":0}`)
  37. data, err := d.GetOpenInfo(c, code)
  38. ctx.Convey("Error should be nil", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. ctx.Convey("data should not be nil", func(ctx convey.C) {
  42. ctx.So(data, convey.ShouldNotBeNil)
  43. })
  44. })
  45. }
  46. func TestDaoGetToken(t *testing.T) {
  47. var (
  48. c = context.TODO()
  49. bid = "abc"
  50. ip = ""
  51. )
  52. convey.Convey("GetToken", t, func(ctx convey.C) {
  53. defer gock.OffAll()
  54. httpMock("GET", d.c.Property.APICoURL+_token).Reply(200).JSON(`{"code":0}`)
  55. _, err := d.GetToken(c, bid, ip)
  56. ctx.Convey("Error should be nil", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. })
  59. })
  60. }
  61. func TestDaoVerify(t *testing.T) {
  62. var (
  63. c = context.TODO()
  64. code = "abc"
  65. token = "abc"
  66. ip = ""
  67. )
  68. convey.Convey("Verify", t, func(ctx convey.C) {
  69. defer gock.OffAll()
  70. httpMock("POST", _verify).Reply(200).JSON(`{"code":0}`)
  71. data, err := d.Verify(c, code, token, ip)
  72. ctx.Convey("Error should be nil", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. })
  75. ctx.Convey("data should not be nil", func(ctx convey.C) {
  76. ctx.So(data, convey.ShouldNotBeNil)
  77. })
  78. })
  79. }
  80. func TestDaoGetPassportDetail(t *testing.T) {
  81. convey.Convey("passport", t, func() {
  82. var mid int64 = 27515586
  83. defer gock.OffAll()
  84. httpMock("GET", _passportDetail).Reply(200).JSON(`{"code":0}`)
  85. _, err := d.GetPassportDetail(context.TODO(), mid)
  86. convey.So(err, convey.ShouldBeNil)
  87. })
  88. }