memcache_test.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/relation/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaostatKey(t *testing.T) {
  9. var (
  10. mid = int64(1)
  11. )
  12. convey.Convey("statKey", t, func(cv convey.C) {
  13. p1 := statKey(mid)
  14. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  15. cv.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestDaotagsKey(t *testing.T) {
  20. var (
  21. mid = int64(1)
  22. )
  23. convey.Convey("tagsKey", t, func(cv convey.C) {
  24. p1 := tagsKey(mid)
  25. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  26. cv.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDaofollowingKey(t *testing.T) {
  31. var (
  32. mid = int64(1)
  33. )
  34. convey.Convey("followingKey", t, func(cv convey.C) {
  35. p1 := followingKey(mid)
  36. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  37. cv.So(p1, convey.ShouldNotBeNil)
  38. })
  39. })
  40. }
  41. func TestDaofollowerKey(t *testing.T) {
  42. var (
  43. mid = int64(1)
  44. )
  45. convey.Convey("followerKey", t, func(cv convey.C) {
  46. p1 := followerKey(mid)
  47. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  48. cv.So(p1, convey.ShouldNotBeNil)
  49. })
  50. })
  51. }
  52. func TestDaotagCountKey(t *testing.T) {
  53. var (
  54. mid = int64(1)
  55. )
  56. convey.Convey("tagCountKey", t, func(cv convey.C) {
  57. p1 := tagCountKey(mid)
  58. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  59. cv.So(p1, convey.ShouldNotBeNil)
  60. })
  61. })
  62. }
  63. func TestDaoglobalHotKey(t *testing.T) {
  64. convey.Convey("globalHotKey", t, func(cv convey.C) {
  65. p1 := globalHotKey()
  66. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  67. cv.So(p1, convey.ShouldNotBeNil)
  68. })
  69. })
  70. }
  71. func TestDaofollowerNotifySetting(t *testing.T) {
  72. var (
  73. mid = int64(1)
  74. )
  75. convey.Convey("followerNotifySetting", t, func(cv convey.C) {
  76. p1 := followerNotifySetting(mid)
  77. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  78. cv.So(p1, convey.ShouldNotBeNil)
  79. })
  80. })
  81. }
  82. func TestDaopingMC(t *testing.T) {
  83. var (
  84. c = context.Background()
  85. )
  86. convey.Convey("pingMC", t, func(cv convey.C) {
  87. err := d.pingMC(c)
  88. cv.Convey("Then err should be nil.", func(cv convey.C) {
  89. cv.So(err, convey.ShouldBeNil)
  90. })
  91. })
  92. }
  93. func TestDaoSetFollowingCache(t *testing.T) {
  94. var (
  95. c = context.Background()
  96. mid = int64(1)
  97. followings = []*model.Following{}
  98. )
  99. convey.Convey("SetFollowingCache", t, func(cv convey.C) {
  100. err := d.SetFollowingCache(c, mid, followings)
  101. cv.Convey("Then err should be nil.", func(cv convey.C) {
  102. cv.So(err, convey.ShouldBeNil)
  103. })
  104. })
  105. }
  106. func TestDaoFollowingCache(t *testing.T) {
  107. var (
  108. c = context.Background()
  109. mid = int64(1)
  110. )
  111. convey.Convey("FollowingCache", t, func(cv convey.C) {
  112. followings, err := d.FollowingCache(c, mid)
  113. cv.Convey("Then err should be nil.followings should not be nil.", func(cv convey.C) {
  114. cv.So(err, convey.ShouldBeNil)
  115. cv.So(followings, convey.ShouldNotBeNil)
  116. })
  117. })
  118. }
  119. func TestDaoDelFollowingCache(t *testing.T) {
  120. var (
  121. c = context.Background()
  122. mid = int64(1)
  123. )
  124. convey.Convey("DelFollowingCache", t, func(cv convey.C) {
  125. err := d.DelFollowingCache(c, mid)
  126. cv.Convey("Then err should be nil.", func(cv convey.C) {
  127. cv.So(err, convey.ShouldBeNil)
  128. })
  129. })
  130. }
  131. func TestDaoSetFollowerCache(t *testing.T) {
  132. var (
  133. c = context.Background()
  134. mid = int64(1)
  135. followers = []*model.Following{}
  136. )
  137. convey.Convey("SetFollowerCache", t, func(cv convey.C) {
  138. err := d.SetFollowerCache(c, mid, followers)
  139. cv.Convey("Then err should be nil.", func(cv convey.C) {
  140. cv.So(err, convey.ShouldBeNil)
  141. })
  142. })
  143. }
  144. func TestDaoFollowerCache(t *testing.T) {
  145. var (
  146. c = context.Background()
  147. mid = int64(1)
  148. )
  149. convey.Convey("FollowerCache", t, func(cv convey.C) {
  150. followers, err := d.FollowerCache(c, mid)
  151. cv.Convey("Then err should be nil.followers should not be nil.", func(cv convey.C) {
  152. cv.So(err, convey.ShouldBeNil)
  153. cv.So(followers, convey.ShouldNotBeNil)
  154. })
  155. })
  156. }
  157. func TestDaoDelFollowerCache(t *testing.T) {
  158. var (
  159. c = context.Background()
  160. mid = int64(1)
  161. )
  162. convey.Convey("DelFollowerCache", t, func(cv convey.C) {
  163. err := d.DelFollowerCache(c, mid)
  164. cv.Convey("Then err should be nil.", func(cv convey.C) {
  165. cv.So(err, convey.ShouldBeNil)
  166. })
  167. })
  168. }
  169. func TestDaosetFollowingCache(t *testing.T) {
  170. var (
  171. c = context.Background()
  172. key = followingKey(1)
  173. followings = []*model.Following{}
  174. )
  175. convey.Convey("setFollowingCache", t, func(cv convey.C) {
  176. err := d.setFollowingCache(c, key, followings)
  177. cv.Convey("Then err should be nil.", func(cv convey.C) {
  178. cv.So(err, convey.ShouldBeNil)
  179. })
  180. })
  181. }
  182. func TestDaofollowingCache(t *testing.T) {
  183. var (
  184. c = context.Background()
  185. key = followingKey(1)
  186. )
  187. convey.Convey("followingCache", t, func(cv convey.C) {
  188. followings, err := d.followingCache(c, key)
  189. cv.Convey("Then err should be nil.followings should not be nil.", func(cv convey.C) {
  190. cv.So(err, convey.ShouldBeNil)
  191. cv.So(followings, convey.ShouldNotBeNil)
  192. })
  193. })
  194. }
  195. func TestDaodelFollowingCache(t *testing.T) {
  196. var (
  197. c = context.Background()
  198. key = followingKey(1)
  199. )
  200. convey.Convey("delFollowingCache", t, func(cv convey.C) {
  201. err := d.delFollowingCache(c, key)
  202. cv.Convey("Then err should be nil.", func(cv convey.C) {
  203. cv.So(err, convey.ShouldBeNil)
  204. })
  205. })
  206. }
  207. func TestDaoTagCountCache(t *testing.T) {
  208. var (
  209. c = context.Background()
  210. mid = int64(1)
  211. tagCount = []*model.TagCount{
  212. {
  213. Tagid: 1,
  214. Name: "test",
  215. Count: 1,
  216. },
  217. }
  218. )
  219. convey.Convey("TagCountCache", t, func(cv convey.C) {
  220. err := d.SetTagCountCache(c, mid, tagCount)
  221. cv.So(err, convey.ShouldBeNil)
  222. tagCount, err := d.TagCountCache(c, mid)
  223. cv.So(err, convey.ShouldBeNil)
  224. cv.So(tagCount, convey.ShouldNotBeNil)
  225. err = d.DelTagCountCache(c, mid)
  226. cv.So(err, convey.ShouldBeNil)
  227. })
  228. }
  229. func TestDaoTagsCache(t *testing.T) {
  230. var (
  231. c = context.Background()
  232. mid = int64(1)
  233. tags = &model.Tags{
  234. Tags: map[int64]*model.Tag{
  235. 1: {
  236. Id: 1,
  237. Name: "1",
  238. Status: 1,
  239. },
  240. },
  241. }
  242. )
  243. convey.Convey("TagsCache", t, func(cv convey.C) {
  244. err := d.SetTagsCache(c, mid, tags)
  245. cv.Convey("SetTagsCache; Then err should be nil.", func(cv convey.C) {
  246. cv.So(err, convey.ShouldBeNil)
  247. })
  248. tags, err := d.TagsCache(c, mid)
  249. cv.Convey("TagsCache; Then err should be nil.tags should not be nil.", func(cv convey.C) {
  250. cv.So(err, convey.ShouldBeNil)
  251. cv.So(tags, convey.ShouldNotBeNil)
  252. })
  253. err = d.DelTagsCache(c, mid)
  254. cv.Convey("DelTagsCache; Then err should be nil.", func(cv convey.C) {
  255. cv.So(err, convey.ShouldBeNil)
  256. })
  257. })
  258. }
  259. func TestDaoSetGlobalHotRecCache(t *testing.T) {
  260. var (
  261. c = context.Background()
  262. fids = []int64{1}
  263. )
  264. convey.Convey("SetGlobalHotRecCache", t, func(cv convey.C) {
  265. err := d.SetGlobalHotRecCache(c, fids)
  266. cv.Convey("Then err should be nil.", func(cv convey.C) {
  267. cv.So(err, convey.ShouldBeNil)
  268. })
  269. })
  270. }
  271. func TestDaoGlobalHotRecCache(t *testing.T) {
  272. var (
  273. c = context.Background()
  274. )
  275. convey.Convey("GlobalHotRecCache", t, func(cv convey.C) {
  276. fs, err := d.GlobalHotRecCache(c)
  277. cv.Convey("Then err should be nil.fs should not be nil.", func(cv convey.C) {
  278. cv.So(err, convey.ShouldBeNil)
  279. cv.So(fs, convey.ShouldNotBeNil)
  280. })
  281. })
  282. }
  283. func TestDaostatCache(t *testing.T) {
  284. var (
  285. c = context.Background()
  286. mid = int64(1)
  287. st = &model.Stat{
  288. Mid: 1,
  289. Follower: 1,
  290. Following: 1,
  291. Black: 1,
  292. Whisper: 1,
  293. }
  294. )
  295. convey.Convey("statCache", t, func(cv convey.C) {
  296. err := d.SetStatCache(c, mid, st)
  297. cv.Convey("SetStatCache; Then err should be nil.", func(cv convey.C) {
  298. cv.So(err, convey.ShouldBeNil)
  299. })
  300. s1, err := d.statCache(c, mid)
  301. cv.Convey("statCache; Then err should be nil.p1 should not be nil.", func(cv convey.C) {
  302. cv.So(err, convey.ShouldBeNil)
  303. cv.So(s1, convey.ShouldNotBeNil)
  304. })
  305. p1, p2, err := d.statsCache(c, []int64{1})
  306. cv.Convey("statsCache; Then err should be nil.p1,p2 should not be nil.", func(cv convey.C) {
  307. cv.So(err, convey.ShouldBeNil)
  308. cv.So(p2, convey.ShouldNotBeNil)
  309. cv.So(p1, convey.ShouldNotBeNil)
  310. })
  311. err = d.DelStatCache(c, mid)
  312. cv.Convey("DelStatCache; Then err should be nil.", func(cv convey.C) {
  313. cv.So(err, convey.ShouldBeNil)
  314. })
  315. })
  316. }
  317. func TestDaoGetFollowerNotifyCache(t *testing.T) {
  318. var (
  319. c = context.Background()
  320. mid = int64(1)
  321. val = &model.FollowerNotifySetting{
  322. Mid: 1,
  323. Enabled: true,
  324. }
  325. )
  326. convey.Convey("GetFollowerNotifyCache", t, func(cv convey.C) {
  327. err := d.SetFollowerNotifyCache(c, mid, val)
  328. cv.Convey("SetFollowerNotifyCache; Then err should be nil.", func(cv convey.C) {
  329. cv.So(err, convey.ShouldBeNil)
  330. })
  331. res, err := d.GetFollowerNotifyCache(c, mid)
  332. cv.Convey("GetFollowerNotifyCache; Then err should be nil.res should not be nil.", func(cv convey.C) {
  333. cv.So(err, convey.ShouldBeNil)
  334. cv.So(res, convey.ShouldNotBeNil)
  335. })
  336. err = d.DelFollowerNotifyCache(c, mid)
  337. cv.Convey("DelFollowerNotifyCache; Then err should be nil.", func(cv convey.C) {
  338. cv.So(err, convey.ShouldBeNil)
  339. })
  340. })
  341. }