rank_test.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. package mcndao
  2. import (
  3. "testing"
  4. "time"
  5. "go-common/app/interface/main/mcn/model/mcnmodel"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestMcndaobyValueDesc(t *testing.T) {
  9. convey.Convey("byValueDesc", t, func(ctx convey.C) {
  10. var (
  11. p1 = &mcnmodel.RankUpFansInfo{Mid: 1}
  12. p2 = &mcnmodel.RankUpFansInfo{Mid: 2}
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. p1 := byValueDesc(p1, p2)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestMcndaoGetRankUpFans(t *testing.T) {
  23. convey.Convey("GetRankUpFans", t, func(ctx convey.C) {
  24. var (
  25. signID = int64(0)
  26. )
  27. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  28. result, err := d.GetRankUpFans(signID)
  29. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.So(result, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestMcndaoGetRankArchiveLikes(t *testing.T) {
  37. convey.Convey("GetRankArchiveLikes", t, func(ctx convey.C) {
  38. var (
  39. signID = int64(0)
  40. )
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. result, err := d.GetRankArchiveLikes(signID)
  43. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. ctx.So(result, convey.ShouldNotBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestMcndaogetRankCache(t *testing.T) {
  51. convey.Convey("getRankCache", t, func(ctx convey.C) {
  52. var (
  53. signID = int64(1)
  54. keyCalc keyFunc
  55. load loadRankFunc
  56. )
  57. keyCalc = cacheKeyRankFans
  58. load = d.loadRankUpFansCache
  59. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  60. result, err := d.getRankCache(signID, keyCalc, load)
  61. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. if result == nil {
  64. ctx.So(result, convey.ShouldBeNil)
  65. } else {
  66. ctx.So(result, convey.ShouldNotBeNil)
  67. }
  68. })
  69. })
  70. })
  71. }
  72. func TestMcndaocacheKeyRankFans(t *testing.T) {
  73. convey.Convey("cacheKeyRankFans", t, func(ctx convey.C) {
  74. var (
  75. signID = int64(0)
  76. )
  77. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  78. p1 := cacheKeyRankFans(signID)
  79. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  80. ctx.So(p1, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestMcndaocacheKeyRankArchiveLikes(t *testing.T) {
  86. convey.Convey("cacheKeyRankArchiveLikes", t, func(ctx convey.C) {
  87. var (
  88. signID = int64(0)
  89. )
  90. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  91. p1 := cacheKeyRankArchiveLikes(signID)
  92. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  93. ctx.So(p1, convey.ShouldNotBeNil)
  94. })
  95. })
  96. })
  97. }
  98. func TestMcndaoloadRankUpFansCache(t *testing.T) {
  99. convey.Convey("loadRankUpFansCache", t, func(ctx convey.C) {
  100. var (
  101. signID = int64(0)
  102. date = time.Now()
  103. )
  104. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  105. result, err := d.loadRankUpFansCache(signID, date)
  106. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(result, convey.ShouldNotBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestMcndaoRawRankUpFans(t *testing.T) {
  114. convey.Convey("RawRankUpFans", t, func(ctx convey.C) {
  115. var (
  116. signID = int64(1)
  117. date = time.Now()
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. result, err := d.RawRankUpFans(signID, date)
  121. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. if len(result) == 0 {
  124. ctx.So(result, convey.ShouldBeNil)
  125. } else {
  126. ctx.So(result, convey.ShouldNotBeNil)
  127. }
  128. })
  129. })
  130. })
  131. }
  132. func TestMcndaoReloadRank(t *testing.T) {
  133. convey.Convey("ReloadRank", t, func(ctx convey.C) {
  134. var (
  135. signID = int64(0)
  136. )
  137. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  138. err := d.ReloadRank(signID)
  139. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  140. ctx.So(err, convey.ShouldBeNil)
  141. })
  142. })
  143. })
  144. }
  145. func TestMcndaoloadRankArchiveLikesCache(t *testing.T) {
  146. convey.Convey("loadRankArchiveLikesCache", t, func(ctx convey.C) {
  147. var (
  148. signID = int64(0)
  149. date = time.Now()
  150. )
  151. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  152. result, err := d.loadRankArchiveLikesCache(signID, date)
  153. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  154. ctx.So(err, convey.ShouldBeNil)
  155. ctx.So(result, convey.ShouldNotBeNil)
  156. })
  157. })
  158. })
  159. }
  160. func TestMcndaoRawRankArchiveLikes(t *testing.T) {
  161. convey.Convey("RawRankArchiveLikes", t, func(ctx convey.C) {
  162. var (
  163. signID = int64(1)
  164. date = time.Now()
  165. )
  166. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  167. result, err := d.RawRankArchiveLikes(signID, date)
  168. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  169. ctx.So(err, convey.ShouldBeNil)
  170. if len(result) == 0 {
  171. ctx.So(result, convey.ShouldBeEmpty)
  172. } else {
  173. ctx.So(result, convey.ShouldNotBeNil)
  174. }
  175. })
  176. })
  177. })
  178. }