ugc_playurl_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package goblin
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "go-common/app/interface/main/tv/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. gock "gopkg.in/h2non/gock.v1"
  9. )
  10. func TestGoblinUgcPlayurl(t *testing.T) {
  11. var (
  12. ctx = context.Background()
  13. p = &model.PlayURLReq{
  14. Cid: fmt.Sprintf("%d", 10131156),
  15. }
  16. )
  17. convey.Convey("UgcPlayurl", t, func(c convey.C) {
  18. defer gock.OffAll()
  19. c.Convey("Normal Situation, Then err should be nil.res,resp should not be nil.", func(cx convey.C) {
  20. httpMock("GET", d.conf.Host.UgcPlayURL).Reply(200).JSON(`{
  21. "result": "succ",
  22. "message": "succ",
  23. "code": 0
  24. }`)
  25. res, resp, err := d.UgcPlayurl(ctx, p)
  26. fmt.Println(resp)
  27. cx.So(err, convey.ShouldBeNil)
  28. cx.So(resp, convey.ShouldNotBeNil)
  29. cx.So(res, convey.ShouldNotBeNil)
  30. })
  31. c.Convey("Request Error", func(cx convey.C) {
  32. httpMock("GET", d.conf.Host.UgcPlayURL).Reply(404).JSON(``)
  33. _, _, err := d.UgcPlayurl(ctx, p)
  34. cx.So(err, convey.ShouldNotBeNil)
  35. })
  36. c.Convey("Code Error", func(cx convey.C) {
  37. httpMock("GET", d.conf.Host.UgcPlayURL).Reply(200).JSON(`{"code":-400}`)
  38. _, _, err := d.UgcPlayurl(ctx, p)
  39. cx.So(err, convey.ShouldNotBeNil)
  40. })
  41. c.Convey("Json Error", func(cx convey.C) {
  42. httpMock("GET", d.conf.Host.UgcPlayURL).Reply(200).JSON(`{"code":-400:}`)
  43. _, _, err := d.UgcPlayurl(ctx, p)
  44. cx.So(err, convey.ShouldNotBeNil)
  45. })
  46. })
  47. }