recommend_pool_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package mcndao
  2. import (
  3. "go-common/app/interface/main/mcn/model/mcnmodel"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestMcndaoadd(t *testing.T) {
  8. convey.Convey("add", t, func(ctx convey.C) {
  9. var (
  10. v = &mcnmodel.McnGetRecommendPoolInfo{}
  11. s = &RecommendPoolCache{}
  12. )
  13. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  14. s.add(v)
  15. ctx.Convey("No return values", func(ctx convey.C) {
  16. })
  17. })
  18. })
  19. }
  20. func TestMcndaoLen(t *testing.T) {
  21. var (
  22. s = &RecommendDataSorter{}
  23. )
  24. convey.Convey("Len", t, func(ctx convey.C) {
  25. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  26. p1 := s.Len()
  27. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  28. ctx.So(p1, convey.ShouldNotBeNil)
  29. })
  30. })
  31. })
  32. }
  33. func TestMcndaoRecommendSortByFansDesc(t *testing.T) {
  34. convey.Convey("RecommendSortByFansDesc", t, func(ctx convey.C) {
  35. var (
  36. p1 = &mcnmodel.McnGetRecommendPoolInfo{}
  37. p2 = &mcnmodel.McnGetRecommendPoolInfo{}
  38. )
  39. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  40. p1 := RecommendSortByFansDesc(p1, p2)
  41. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestMcndaoRecommendSortByFansAsc(t *testing.T) {
  48. convey.Convey("RecommendSortByFansAsc", t, func(ctx convey.C) {
  49. var (
  50. p1 = &mcnmodel.McnGetRecommendPoolInfo{}
  51. p2 = &mcnmodel.McnGetRecommendPoolInfo{}
  52. )
  53. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  54. p1 := RecommendSortByFansAsc(p1, p2)
  55. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  56. ctx.So(p1, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestMcndaoRecommendSortByMonthFansDesc(t *testing.T) {
  62. convey.Convey("RecommendSortByMonthFansDesc", t, func(ctx convey.C) {
  63. var (
  64. p1 = &mcnmodel.McnGetRecommendPoolInfo{}
  65. p2 = &mcnmodel.McnGetRecommendPoolInfo{}
  66. )
  67. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  68. p1 := RecommendSortByMonthFansDesc(p1, p2)
  69. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  70. ctx.So(p1, convey.ShouldNotBeNil)
  71. })
  72. })
  73. })
  74. }
  75. func TestMcndaoRecommendSortByArchiveCountDesc(t *testing.T) {
  76. convey.Convey("RecommendSortByArchiveCountDesc", t, func(ctx convey.C) {
  77. var (
  78. p1 = &mcnmodel.McnGetRecommendPoolInfo{}
  79. p2 = &mcnmodel.McnGetRecommendPoolInfo{}
  80. )
  81. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  82. p1 := RecommendSortByArchiveCountDesc(p1, p2)
  83. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  84. ctx.So(p1, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestMcndaocacheKeyRecommend(t *testing.T) {
  90. convey.Convey("cacheKeyRecommend", t, func(ctx convey.C) {
  91. var (
  92. a1 = int64(0)
  93. )
  94. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  95. p1 := cacheKeyRecommend(a1)
  96. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  97. ctx.So(p1, convey.ShouldNotBeNil)
  98. })
  99. })
  100. })
  101. }
  102. func TestMcndaorawGetRecommendPool(t *testing.T) {
  103. convey.Convey("rawGetRecommendPool", t, func(ctx convey.C) {
  104. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  105. res, err := d.rawGetRecommendPool()
  106. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. ctx.So(len(res), convey.ShouldBeGreaterThanOrEqualTo, 0)
  109. })
  110. })
  111. })
  112. }
  113. func TestMcndaoloadRecommendPool(t *testing.T) {
  114. convey.Convey("loadRecommendPool", t, func(ctx convey.C) {
  115. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  116. res, err := d.loadRecommendPool()
  117. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  118. ctx.So(err, convey.ShouldBeNil)
  119. ctx.So(res, convey.ShouldNotBeNil)
  120. })
  121. })
  122. })
  123. }
  124. func TestMcndaogetRecommendCache(t *testing.T) {
  125. convey.Convey("getRecommendCache", t, func(ctx convey.C) {
  126. var (
  127. keyCalc = cacheKeyRecommend
  128. load = d.loadRecommendPool
  129. )
  130. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  131. result, err := d.getRecommendCache(keyCalc, load)
  132. ctx.Convey("Then err should be nil.result should not be nil.", func(ctx convey.C) {
  133. ctx.So(err, convey.ShouldBeNil)
  134. ctx.So(result, convey.ShouldNotBeNil)
  135. })
  136. })
  137. })
  138. }
  139. func TestMcndaoGetRecommendPool(t *testing.T) {
  140. convey.Convey("GetRecommendPool", t, func(ctx convey.C) {
  141. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  142. res, err := d.GetRecommendPool()
  143. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  144. ctx.So(err, convey.ShouldBeNil)
  145. ctx.So(res, convey.ShouldNotBeNil)
  146. })
  147. })
  148. })
  149. }