redis_test.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/relation/model"
  5. xtime "go-common/library/time"
  6. "testing"
  7. gtime "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaofollowingsKey(t *testing.T) {
  11. var (
  12. mid = int64(1)
  13. )
  14. convey.Convey("followingsKey", t, func(cv convey.C) {
  15. p1 := followingsKey(mid)
  16. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  17. cv.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func TestDaomonitorKey(t *testing.T) {
  22. convey.Convey("monitorKey", t, func(cv convey.C) {
  23. p1 := monitorKey()
  24. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  25. cv.So(p1, convey.ShouldNotBeNil)
  26. })
  27. })
  28. }
  29. func TestDaorecentFollower(t *testing.T) {
  30. var (
  31. mid = int64(1)
  32. )
  33. convey.Convey("recentFollower", t, func(cv convey.C) {
  34. p1 := recentFollower(mid)
  35. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  36. cv.So(p1, convey.ShouldNotBeNil)
  37. })
  38. })
  39. }
  40. func TestDaorecentFollowerNotify(t *testing.T) {
  41. var (
  42. mid = int64(1)
  43. )
  44. convey.Convey("recentFollowerNotify", t, func(cv convey.C) {
  45. p1 := recentFollowerNotify(mid)
  46. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  47. cv.So(p1, convey.ShouldNotBeNil)
  48. })
  49. })
  50. }
  51. func TestDaodailyNotifyCount(t *testing.T) {
  52. var (
  53. mid = int64(1)
  54. date gtime.Time
  55. )
  56. convey.Convey("dailyNotifyCount", t, func(cv convey.C) {
  57. p1 := dailyNotifyCount(mid, date)
  58. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  59. cv.So(p1, convey.ShouldNotBeNil)
  60. })
  61. })
  62. }
  63. func TestDaopingRedis(t *testing.T) {
  64. var (
  65. c = context.Background()
  66. )
  67. convey.Convey("pingRedis", t, func(cv convey.C) {
  68. err := d.pingRedis(c)
  69. cv.Convey("Then err should be nil.", func(cv convey.C) {
  70. cv.So(err, convey.ShouldBeNil)
  71. })
  72. })
  73. }
  74. func TestDaoFollowingsCache(t *testing.T) {
  75. var (
  76. c = context.Background()
  77. mid = int64(1)
  78. )
  79. convey.Convey("FollowingsCache", t, func(cv convey.C) {
  80. err := d.SetFollowingsCache(c, mid, []*model.Following{
  81. {Mid: 2},
  82. })
  83. cv.Convey("SetFollowingsCache; Then err should be nil.", func(cv convey.C) {
  84. cv.So(err, convey.ShouldBeNil)
  85. })
  86. err = d.AddFollowingCache(c, mid, &model.Following{Mid: 2})
  87. cv.Convey("AddFollowingCache; Then err should be nil.", func(cv convey.C) {
  88. cv.So(err, convey.ShouldBeNil)
  89. })
  90. followings, err := d.FollowingsCache(c, mid)
  91. cv.Convey("FollowingsCache; Then err should be nil.followings should not be nil.", func(cv convey.C) {
  92. cv.So(err, convey.ShouldBeNil)
  93. cv.So(followings, convey.ShouldNotBeNil)
  94. })
  95. err = d.DelFollowing(c, mid, &model.Following{Mid: 2})
  96. cv.Convey("DelFollowing; Then err should be nil.", func(cv convey.C) {
  97. cv.So(err, convey.ShouldBeNil)
  98. })
  99. })
  100. }
  101. func TestDaoDelFollowingsCache(t *testing.T) {
  102. var (
  103. c = context.Background()
  104. mid = int64(0)
  105. )
  106. convey.Convey("DelFollowingsCache", t, func(cv convey.C) {
  107. err := d.DelFollowingsCache(c, mid)
  108. cv.Convey("Then err should be nil.", func(cv convey.C) {
  109. cv.So(err, convey.ShouldBeNil)
  110. })
  111. })
  112. }
  113. func TestDaoRelationsCache(t *testing.T) {
  114. var (
  115. c = context.Background()
  116. mid = int64(1)
  117. fids = []int64{2}
  118. )
  119. convey.Convey("RelationsCache", t, func(cv convey.C) {
  120. resMap, err := d.RelationsCache(c, mid, fids)
  121. cv.Convey("Then err should be nil.resMap should not be nil.", func(cv convey.C) {
  122. cv.So(err, convey.ShouldBeNil)
  123. cv.So(resMap, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoencode(t *testing.T) {
  128. var (
  129. attribute = uint32(0)
  130. mtime = xtime.Time(int64(0))
  131. tagids = []int64{}
  132. special = int32(0)
  133. )
  134. convey.Convey("encode", t, func(cv convey.C) {
  135. res, err := d.encode(attribute, mtime, tagids, special)
  136. cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
  137. cv.So(err, convey.ShouldBeNil)
  138. cv.So(res, convey.ShouldNotBeNil)
  139. })
  140. })
  141. }
  142. func TestDaodecode(t *testing.T) {
  143. var (
  144. src = []byte("")
  145. v = &model.FollowingTags{}
  146. )
  147. convey.Convey("decode", t, func(cv convey.C) {
  148. err := d.decode(src, v)
  149. cv.Convey("Then err should be nil.", func(cv convey.C) {
  150. cv.So(err, convey.ShouldBeNil)
  151. })
  152. })
  153. }
  154. func TestDaoMonitorCache(t *testing.T) {
  155. var (
  156. c = context.Background()
  157. mid = int64(0)
  158. )
  159. convey.Convey("MonitorCache", t, func(cv convey.C) {
  160. exist, err := d.MonitorCache(c, mid)
  161. cv.Convey("Then err should be nil.exist should not be nil.", func(cv convey.C) {
  162. cv.So(err, convey.ShouldBeNil)
  163. cv.So(exist, convey.ShouldNotBeNil)
  164. })
  165. })
  166. }
  167. func TestDaoSetMonitorCache(t *testing.T) {
  168. var (
  169. c = context.Background()
  170. mid = int64(0)
  171. )
  172. convey.Convey("SetMonitorCache", t, func(cv convey.C) {
  173. err := d.SetMonitorCache(c, mid)
  174. cv.Convey("Then err should be nil.", func(cv convey.C) {
  175. cv.So(err, convey.ShouldBeNil)
  176. })
  177. })
  178. }
  179. func TestDaoDelMonitorCache(t *testing.T) {
  180. var (
  181. c = context.Background()
  182. mid = int64(0)
  183. )
  184. convey.Convey("DelMonitorCache", t, func(cv convey.C) {
  185. err := d.DelMonitorCache(c, mid)
  186. cv.Convey("Then err should be nil.", func(cv convey.C) {
  187. cv.So(err, convey.ShouldBeNil)
  188. })
  189. })
  190. }
  191. func TestDaoLoadMonitorCache(t *testing.T) {
  192. var (
  193. c = context.Background()
  194. mids = []int64{}
  195. )
  196. convey.Convey("LoadMonitorCache", t, func(cv convey.C) {
  197. err := d.LoadMonitorCache(c, mids)
  198. cv.Convey("Then err should be nil.", func(cv convey.C) {
  199. cv.So(err, convey.ShouldBeNil)
  200. })
  201. })
  202. }
  203. func TestDaoTodayNotifyCountCache(t *testing.T) {
  204. var (
  205. c = context.Background()
  206. mid = int64(0)
  207. )
  208. convey.Convey("TodayNotifyCountCache", t, func(cv convey.C) {
  209. notifyCount, err := d.TodayNotifyCountCache(c, mid)
  210. cv.Convey("Then err should be nil.notifyCount should not be nil.", func(cv convey.C) {
  211. cv.So(err, convey.ShouldBeNil)
  212. cv.So(notifyCount, convey.ShouldNotBeNil)
  213. })
  214. })
  215. }
  216. func TestDaoIncrTodayNotifyCountCache(t *testing.T) {
  217. var (
  218. c = context.Background()
  219. mid = int64(0)
  220. )
  221. convey.Convey("IncrTodayNotifyCount", t, func(cv convey.C) {
  222. err := d.IncrTodayNotifyCount(c, mid)
  223. cv.Convey("Then err should be nil.", func(cv convey.C) {
  224. cv.So(err, convey.ShouldBeNil)
  225. })
  226. })
  227. }