upper_rds_test.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package archive
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/library/time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestArchiveupCntKey(t *testing.T) {
  9. var (
  10. mid = int64(1)
  11. )
  12. convey.Convey("upCntKey", t, func(ctx convey.C) {
  13. p1 := upCntKey(mid)
  14. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestArchiveupPasKey(t *testing.T) {
  20. var (
  21. mid = int64(1)
  22. )
  23. convey.Convey("upPasKey", t, func(ctx convey.C) {
  24. p1 := upPasKey(mid)
  25. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  26. ctx.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestArchiveAddUpperCountCache(t *testing.T) {
  31. var (
  32. c = context.TODO()
  33. mid = int64(1)
  34. count = int64(10)
  35. )
  36. convey.Convey("AddUpperCountCache", t, func(ctx convey.C) {
  37. err := d.AddUpperCountCache(c, mid, count)
  38. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. })
  42. }
  43. func TestArchiveUpperCountCache(t *testing.T) {
  44. var (
  45. c = context.TODO()
  46. mid = int64(1)
  47. )
  48. convey.Convey("UpperCountCache", t, func(ctx convey.C) {
  49. count, err := d.UpperCountCache(c, mid)
  50. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(count, convey.ShouldNotBeNil)
  53. })
  54. })
  55. }
  56. func TestArchiveUppersCountCache(t *testing.T) {
  57. var (
  58. c = context.TODO()
  59. mids = []int64{1, 2}
  60. )
  61. convey.Convey("UppersCountCache", t, func(ctx convey.C) {
  62. cached, missed, err := d.UppersCountCache(c, mids)
  63. ctx.Convey("Then err should be nil.cached,missed should not be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. ctx.So(missed, convey.ShouldNotBeNil)
  66. ctx.So(cached, convey.ShouldNotBeNil)
  67. })
  68. })
  69. }
  70. func TestArchiveUpperPassedCache(t *testing.T) {
  71. var (
  72. c = context.TODO()
  73. mid = int64(1)
  74. start = int(0)
  75. end = int(10)
  76. )
  77. convey.Convey("UpperPassedCache", t, func(ctx convey.C) {
  78. _, err := d.UpperPassedCache(c, mid, start, end)
  79. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. })
  82. })
  83. }
  84. func TestArchiveUppersPassedCacheWithScore(t *testing.T) {
  85. var (
  86. c = context.TODO()
  87. mids = []int64{1, 2}
  88. start = int(0)
  89. end = int(10)
  90. )
  91. convey.Convey("UppersPassedCacheWithScore", t, func(ctx convey.C) {
  92. aidm, err := d.UppersPassedCacheWithScore(c, mids, start, end)
  93. ctx.Convey("Then err should be nil.aidm should not be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(aidm, convey.ShouldNotBeNil)
  96. })
  97. })
  98. }
  99. func TestArchiveUppersPassedCache(t *testing.T) {
  100. var (
  101. c = context.TODO()
  102. mids = []int64{1, 2}
  103. start = int(0)
  104. end = int(10)
  105. )
  106. convey.Convey("UppersPassedCache", t, func(ctx convey.C) {
  107. aidm, err := d.UppersPassedCache(c, mids, start, end)
  108. ctx.Convey("Then err should be nil.aidm should not be nil.", func(ctx convey.C) {
  109. ctx.So(err, convey.ShouldBeNil)
  110. ctx.So(aidm, convey.ShouldNotBeNil)
  111. })
  112. })
  113. }
  114. func TestArchiveExpireUpperPassedCache(t *testing.T) {
  115. var (
  116. c = context.TODO()
  117. mid = int64(1)
  118. )
  119. convey.Convey("ExpireUpperPassedCache", t, func(ctx convey.C) {
  120. ok, err := d.ExpireUpperPassedCache(c, mid)
  121. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(ok, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestArchiveExpireUppersCountCache(t *testing.T) {
  128. var (
  129. c = context.TODO()
  130. mids = []int64{1, 2}
  131. )
  132. convey.Convey("ExpireUppersCountCache", t, func(ctx convey.C) {
  133. cachedUp, missed, err := d.ExpireUppersCountCache(c, mids)
  134. ctx.Convey("Then err should be nil.cachedUp,missed should not be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. ctx.So(missed, convey.ShouldNotBeNil)
  137. ctx.So(cachedUp, convey.ShouldNotBeNil)
  138. })
  139. })
  140. }
  141. func TestArchiveExpireUppersPassedCache(t *testing.T) {
  142. var (
  143. c = context.TODO()
  144. mids = []int64{1, 2}
  145. )
  146. convey.Convey("ExpireUppersPassedCache", t, func(ctx convey.C) {
  147. res, err := d.ExpireUppersPassedCache(c, mids)
  148. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  149. ctx.So(err, convey.ShouldBeNil)
  150. ctx.So(res, convey.ShouldNotBeNil)
  151. })
  152. })
  153. }
  154. func TestArchiveAddUpperPassedCache(t *testing.T) {
  155. var (
  156. c = context.TODO()
  157. mid = int64(1)
  158. aids = []int64{1}
  159. ptimes = []time.Time{1531553274}
  160. copyrights = []int8{1}
  161. )
  162. convey.Convey("AddUpperPassedCache", t, func(ctx convey.C) {
  163. err := d.AddUpperPassedCache(c, mid, aids, ptimes, copyrights)
  164. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  165. ctx.So(err, convey.ShouldBeNil)
  166. })
  167. })
  168. }
  169. func TestArchiveDelUpperPassedCache(t *testing.T) {
  170. var (
  171. c = context.TODO()
  172. mid = int64(1)
  173. aid = int64(1)
  174. )
  175. convey.Convey("DelUpperPassedCache", t, func(ctx convey.C) {
  176. err := d.DelUpperPassedCache(c, mid, aid)
  177. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  178. ctx.So(err, convey.ShouldBeNil)
  179. })
  180. })
  181. }