playurl_test.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoPlayurl(t *testing.T) {
  8. var (
  9. ctx = context.Background()
  10. cid = int(0)
  11. normalStr = `{"Code":0,"Durl":[{"URL":"test"}]}`
  12. httpStr = `{"Code":-400,"Durl":[{"URL":"test"}]}`
  13. emptyStr = `{"Code":0,"Durl":[]}`
  14. )
  15. convey.Convey("Playurl", t, func(cx convey.C) {
  16. cx.Convey("Normal Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  17. httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(normalStr)
  18. playurl, err := d.Playurl(ctx, cid)
  19. cx.So(err, convey.ShouldBeNil)
  20. cx.So(playurl, convey.ShouldNotBeNil)
  21. })
  22. cx.Convey("Http Err Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  23. httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(httpStr)
  24. _, err := d.Playurl(ctx, cid)
  25. cx.So(err, convey.ShouldNotBeNil)
  26. })
  27. cx.Convey("Empty Durl Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  28. httpMock("GET", d.c.Cfg.PlayurlAPI).Reply(200).JSON(emptyStr)
  29. _, err := d.Playurl(ctx, cid)
  30. cx.So(err, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func TestDaoUPlayurl(t *testing.T) {
  35. var (
  36. ctx = context.Background()
  37. cid = int(0)
  38. normalStr = `{"Code":0,"Durl":[{"URL":"test"}]}`
  39. httpStr = `{"Code":-400,"Durl":[{"URL":"test"}]}`
  40. emptyStr = `{"Code":0,"Durl":[]}`
  41. )
  42. convey.Convey("UPlayurl", t, func(cx convey.C) {
  43. cx.Convey("Normal Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  44. httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(normalStr)
  45. playurl, err := d.UPlayurl(ctx, cid)
  46. cx.So(err, convey.ShouldBeNil)
  47. cx.So(playurl, convey.ShouldNotBeNil)
  48. })
  49. cx.Convey("Http Err Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  50. httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(httpStr)
  51. _, err := d.UPlayurl(ctx, cid)
  52. cx.So(err, convey.ShouldNotBeNil)
  53. })
  54. cx.Convey("Empty Durl Situation. Then err should be nil.playurl should not be nil.", func(cx convey.C) {
  55. httpMock("GET", d.c.Cfg.UPlayurlAPI).Reply(200).JSON(emptyStr)
  56. _, err := d.UPlayurl(ctx, cid)
  57. cx.So(err, convey.ShouldNotBeNil)
  58. })
  59. })
  60. }