notify_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. gock "gopkg.in/h2non/gock.v1"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. // go test -test.v -test.run TestDaoNotifyRet
  9. func TestDaoNotifyRet(t *testing.T) {
  10. convey.Convey("NotifyRet", t, func(convCtx convey.C) {
  11. var (
  12. c = context.Background()
  13. notifyURL = "http://bangumi.bilibili.com/pay/inner/notify_ticket"
  14. ticketNO = "706821058124120180326154"
  15. orderNO = "20180326153703795"
  16. ip = "127.0.0.1"
  17. )
  18. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  19. data, err := d.NotifyRet(c, notifyURL, ticketNO, orderNO, ip)
  20. t.Logf("data (%v)", data)
  21. convCtx.Convey("Then err should be nil.data should not be nil.", func(convCtx convey.C) {
  22. convCtx.So(err, convey.ShouldBeNil)
  23. convCtx.So(data, convey.ShouldNotBeNil)
  24. })
  25. convCtx.Convey("res.Code!=0 Then err should not be nil.data should be nil.", func(convCtx convey.C) {
  26. defer gock.OffAll()
  27. httpMock("POST", notifyURL).Reply(200).JSON(`{"code":-1}`)
  28. data, err = d.NotifyRet(c, notifyURL, ticketNO, orderNO, ip)
  29. convCtx.So(err, convey.ShouldNotBeNil)
  30. convCtx.So(data, convey.ShouldBeNil)
  31. })
  32. convCtx.Convey("call service error Then err should not be nil.data should be nil.", func(convCtx convey.C) {
  33. defer gock.OffAll()
  34. httpMock("POST", "").Reply(-400).JSON(`{"code":-1}`)
  35. data, err = d.NotifyRet(c, notifyURL, ticketNO, orderNO, ip)
  36. convCtx.So(err, convey.ShouldNotBeNil)
  37. convCtx.So(data, convey.ShouldBeNil)
  38. })
  39. })
  40. })
  41. }