bigdata_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package dao
  2. import (
  3. "testing"
  4. . "github.com/smartystreets/goconvey/convey"
  5. )
  6. func Test_SkyHorse(t *testing.T) {
  7. Convey("normal should get data", t, func() {
  8. data := `{
  9. "code": 0,
  10. "data": [
  11. {
  12. "tid": 1652,
  13. "id": 1,
  14. "goto": "av",
  15. "source": "user_group",
  16. "image_cnt" : 3,
  17. "av_feature": "a"
  18. },
  19. {
  20. "tid": 8227,
  21. "id": 2,
  22. "goto": "av",
  23. "source": "user_group",
  24. "av_feature": "b"
  25. }
  26. ],
  27. "user_feature": "c"
  28. }`
  29. httpMock("GET", d.c.Article.SkyHorseURL).Reply(200).JSON(data)
  30. res, err := d.SkyHorse(ctx(), 1, 0, "", 1, 20)
  31. So(err, ShouldBeNil)
  32. So(res.Data, ShouldNotBeEmpty)
  33. })
  34. Convey("-3 should get data", t, func() {
  35. data := `{
  36. "code": -3,
  37. "data": [
  38. {
  39. "tid": 1652,
  40. "id": 1,
  41. "goto": "av",
  42. "source": "user_group",
  43. "image_cnt" : 3,
  44. "av_feature": "a"
  45. },
  46. {
  47. "tid": 8227,
  48. "id": 2,
  49. "goto": "av",
  50. "source": "user_group",
  51. "av_feature": "b"
  52. }
  53. ],
  54. "user_feature": "c"
  55. }`
  56. httpMock("GET", d.c.Article.SkyHorseURL).Reply(200).JSON(data)
  57. res, err := d.SkyHorse(ctx(), 1, 0, "", 1, 20)
  58. So(err, ShouldBeNil)
  59. So(res.Data, ShouldNotBeEmpty)
  60. })
  61. Convey("code !=0 or -3 should get error", t, func() {
  62. data := `{"code":-10}`
  63. httpMock("GET", d.c.Article.SkyHorseURL).Reply(200).JSON(data)
  64. res, err := d.SkyHorse(ctx(), 1, 0, "", 1, 20)
  65. So(err, ShouldNotBeNil)
  66. So(res.Data, ShouldBeEmpty)
  67. })
  68. }