bigdata_test.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. "gopkg.in/h2non/gock.v1"
  7. )
  8. func TestDaoRanking(t *testing.T) {
  9. convey.Convey("Ranking", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. rid = int16(0)
  13. rankType = int(0)
  14. day = int(0)
  15. arcType = int(0)
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. defer gock.OffAll()
  19. httpMock("GET", d.c.Host.Rank+_rankURL).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715,"score":704},{"aid":33913315,"score":571}]}`)
  20. res, err := d.Ranking(c, rid, rankType, day, arcType)
  21. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldBeNil)
  23. ctx.So(res, convey.ShouldNotBeNil)
  24. })
  25. })
  26. })
  27. }
  28. func TestDaoRankingIndex(t *testing.T) {
  29. convey.Convey("RankingIndex", t, func(ctx convey.C) {
  30. var (
  31. c = context.Background()
  32. day = int(1)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. defer gock.OffAll()
  36. httpMock("GET", d.c.Host.Rank+_rankURL).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715,"score":704},{"aid":33913315,"score":571}]}`)
  37. res, err := d.RankingIndex(c, day)
  38. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. ctx.So(res, convey.ShouldNotBeNil)
  41. })
  42. })
  43. })
  44. }
  45. func TestDaoRankingRegion(t *testing.T) {
  46. convey.Convey("RankingRegion", t, func(ctx convey.C) {
  47. var (
  48. c = context.Background()
  49. rid = int16(0)
  50. day = int(0)
  51. original = int(0)
  52. )
  53. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  54. defer gock.OffAll()
  55. httpMock("GET", d.c.Host.Rank+_rankURL).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715,"score":704},{"aid":33913315,"score":571}]}`)
  56. res, err := d.RankingRegion(c, rid, day, original)
  57. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. ctx.So(res, convey.ShouldNotBeNil)
  60. })
  61. })
  62. })
  63. }
  64. func TestDaoRankingRecommend(t *testing.T) {
  65. convey.Convey("RankingRecommend", t, func(ctx convey.C) {
  66. var (
  67. c = context.Background()
  68. rid = int16(0)
  69. )
  70. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  71. defer gock.OffAll()
  72. httpMock("GET", d.c.Host.Rank+_rankURL).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715,"score":704},{"aid":33913315,"score":571}]}`)
  73. res, err := d.RankingRecommend(c, rid)
  74. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  75. ctx.So(err, convey.ShouldBeNil)
  76. ctx.So(res, convey.ShouldNotBeNil)
  77. })
  78. })
  79. })
  80. }
  81. func TestDaoRankingTag(t *testing.T) {
  82. convey.Convey("RankingTag", t, func(ctx convey.C) {
  83. var (
  84. c = context.Background()
  85. rid = int16(0)
  86. tagID = int64(0)
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. defer gock.OffAll()
  90. httpMock("GET", d.c.Host.Rank).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715,"score":704},{"aid":33913315,"score":571}]}`)
  91. rs, err := d.RankingTag(c, rid, tagID)
  92. ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. ctx.So(rs, convey.ShouldNotBeNil)
  95. })
  96. })
  97. })
  98. }
  99. func TestDaoRegionCustom(t *testing.T) {
  100. convey.Convey("RegionCustom", t, func(ctx convey.C) {
  101. var (
  102. c = context.Background()
  103. )
  104. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  105. defer gock.OffAll()
  106. httpMock("GET", d.customURL).Reply(200).JSON(`{"code":0,"num":8,"list":[{"aid":33986715},{"aid":33913315}]}`)
  107. rs, err := d.RegionCustom(c)
  108. ctx.Convey("Then err should be nil.rs should not be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. ctx.So(rs, convey.ShouldNotBeNil)
  111. })
  112. })
  113. })
  114. }
  115. func TestDaorankURI(t *testing.T) {
  116. convey.Convey("rankURI", t, func(ctx convey.C) {
  117. var (
  118. rid = int16(0)
  119. rankType = ""
  120. day = int(0)
  121. arcType = int(0)
  122. )
  123. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  124. p1 := rankURI(rid, rankType, day, arcType)
  125. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  126. ctx.So(p1, convey.ShouldNotBeNil)
  127. })
  128. })
  129. })
  130. }