redis_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/favorite/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestMultiExpireRelations(t *testing.T) {
  9. var (
  10. c = context.TODO()
  11. fids = []int64{1, 2}
  12. mid = int64(0)
  13. )
  14. convey.Convey("RemFidsRedis", t, func(ctx convey.C) {
  15. _, err := d.MultiExpireRelations(c, mid, fids)
  16. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  17. ctx.So(err, convey.ShouldBeNil)
  18. })
  19. })
  20. }
  21. func TestFavRemFidsRedis(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. typ = int8(0)
  25. mid = int64(0)
  26. fs = &model.Folder{}
  27. )
  28. convey.Convey("RemFidsRedis", t, func(ctx convey.C) {
  29. err := d.RemFidsRedis(c, typ, mid, fs)
  30. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. })
  33. })
  34. }
  35. func TestFavfavedBitKey(t *testing.T) {
  36. var (
  37. tp = int8(1)
  38. mid = int64(88888894)
  39. )
  40. convey.Convey("favedBitKey", t, func(ctx convey.C) {
  41. p1 := favedBitKey(tp, mid)
  42. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func TestFavAddRelationCache(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. m = &model.Favorite{
  51. Oid: 1,
  52. Fid: 1,
  53. Mid: 88888894,
  54. Type: 1,
  55. }
  56. )
  57. convey.Convey("AddRelationCache", t, func(ctx convey.C) {
  58. err := d.AddRelationCache(c, m)
  59. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldBeNil)
  61. })
  62. })
  63. }
  64. func TestFavfolderKey(t *testing.T) {
  65. var (
  66. tp = int8(1)
  67. mid = int64(88888894)
  68. )
  69. convey.Convey("folderKey", t, func(ctx convey.C) {
  70. p1 := folderKey(tp, mid)
  71. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  72. ctx.So(p1, convey.ShouldNotBeNil)
  73. })
  74. })
  75. }
  76. func TestFavrelationKey(t *testing.T) {
  77. var (
  78. mid = int64(88888894)
  79. fid = int64(1)
  80. )
  81. convey.Convey("relationKey", t, func(ctx convey.C) {
  82. p1 := relationKey(mid, fid)
  83. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  84. ctx.So(p1, convey.ShouldNotBeNil)
  85. })
  86. })
  87. }
  88. func TestFavrelationOidsKey(t *testing.T) {
  89. var (
  90. tp = int8(1)
  91. mid = int64(88888894)
  92. )
  93. convey.Convey("relationOidsKey", t, func(ctx convey.C) {
  94. p1 := relationOidsKey(tp, mid)
  95. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  96. ctx.So(p1, convey.ShouldNotBeNil)
  97. })
  98. })
  99. }
  100. func TestFavpingRedis(t *testing.T) {
  101. var (
  102. c = context.TODO()
  103. )
  104. convey.Convey("pingRedis", t, func(ctx convey.C) {
  105. err := d.pingRedis(c)
  106. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  107. ctx.So(err, convey.ShouldBeNil)
  108. })
  109. })
  110. }
  111. func TestFavExpireRelations(t *testing.T) {
  112. var (
  113. c = context.TODO()
  114. mid = int64(88888894)
  115. fid = int64(1)
  116. )
  117. convey.Convey("ExpireRelations", t, func(ctx convey.C) {
  118. ok, err := d.ExpireRelations(c, mid, fid)
  119. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  120. ctx.So(err, convey.ShouldBeNil)
  121. ctx.So(ok, convey.ShouldNotBeNil)
  122. })
  123. })
  124. }
  125. func TestFavExpireFolder(t *testing.T) {
  126. var (
  127. c = context.TODO()
  128. tp = int8(1)
  129. mid = int64(88888894)
  130. )
  131. convey.Convey("ExpireFolder", t, func(ctx convey.C) {
  132. ok, err := d.ExpireFolder(c, tp, mid)
  133. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(ok, convey.ShouldNotBeNil)
  136. })
  137. })
  138. }
  139. func TestFavAddFidsRedis(t *testing.T) {
  140. var (
  141. c = context.TODO()
  142. typ = int8(0)
  143. mid = int64(0)
  144. fs = &model.Folder{}
  145. )
  146. convey.Convey("AddFidsRedis", t, func(ctx convey.C) {
  147. err := d.AddFidsRedis(c, typ, mid, fs)
  148. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  149. ctx.So(err, convey.ShouldBeNil)
  150. })
  151. })
  152. }
  153. func TestFavFidsRedis(t *testing.T) {
  154. var (
  155. c = context.TODO()
  156. tp = int8(0)
  157. mid = int64(0)
  158. )
  159. convey.Convey("FidsRedis", t, func(ctx convey.C) {
  160. _, err := d.FidsRedis(c, tp, mid)
  161. ctx.Convey("Then err should be nil.fids should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. })
  164. })
  165. }
  166. func TestFavDelFidsRedis(t *testing.T) {
  167. var (
  168. c = context.TODO()
  169. typ = int8(1)
  170. mid = int64(88888894)
  171. )
  172. convey.Convey("DelFidsRedis", t, func(ctx convey.C) {
  173. err := d.DelFidsRedis(c, typ, mid)
  174. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  175. ctx.So(err, convey.ShouldBeNil)
  176. })
  177. })
  178. }
  179. func TestFavAddFoldersCache(t *testing.T) {
  180. var (
  181. c = context.TODO()
  182. tp = int8(1)
  183. mid = int64(88888894)
  184. folders = []*model.Folder{
  185. &model.Folder{
  186. ID: 1,
  187. },
  188. }
  189. )
  190. convey.Convey("AddFoldersCache", t, func(ctx convey.C) {
  191. err := d.AddFoldersCache(c, tp, mid, folders)
  192. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  193. ctx.So(err, convey.ShouldBeNil)
  194. })
  195. })
  196. }
  197. func TestFavFolderRelationsCache(t *testing.T) {
  198. var (
  199. c = context.TODO()
  200. typ = int8(1)
  201. mid = int64(88888894)
  202. fid = int64(1)
  203. start = int(1)
  204. end = int(2)
  205. )
  206. convey.Convey("FolderRelationsCache", t, func(ctx convey.C) {
  207. _, err := d.FolderRelationsCache(c, typ, mid, fid, start, end)
  208. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  209. ctx.So(err, convey.ShouldBeNil)
  210. })
  211. })
  212. }
  213. func TestFavAllFolderRelationsCache(t *testing.T) {
  214. var (
  215. c = context.TODO()
  216. typ = int8(1)
  217. mid = int64(88888894)
  218. fid = int64(1)
  219. start = int(1)
  220. end = int(2)
  221. )
  222. convey.Convey("FolderAllRelationsCache", t, func(ctx convey.C) {
  223. _, err := d.FolderAllRelationsCache(c, typ, mid, fid, start, end)
  224. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  225. ctx.So(err, convey.ShouldBeNil)
  226. })
  227. })
  228. }
  229. func TestFavCntRelationsCache(t *testing.T) {
  230. var (
  231. c = context.TODO()
  232. mid = int64(88888894)
  233. fid = int64(1)
  234. )
  235. convey.Convey("CntRelationsCache", t, func(ctx convey.C) {
  236. cnt, err := d.CntRelationsCache(c, mid, fid)
  237. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  238. ctx.So(err, convey.ShouldBeNil)
  239. ctx.So(cnt, convey.ShouldNotBeNil)
  240. })
  241. })
  242. }
  243. func TestFavCntAllRelationsCache(t *testing.T) {
  244. var (
  245. c = context.TODO()
  246. mid = int64(88888894)
  247. fid = int64(1)
  248. )
  249. convey.Convey("CntAllRelationsCache", t, func(ctx convey.C) {
  250. cnt, err := d.CntAllRelationsCache(c, mid, fid)
  251. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  252. ctx.So(err, convey.ShouldBeNil)
  253. ctx.So(cnt, convey.ShouldNotBeNil)
  254. })
  255. })
  256. }
  257. func TestFavExpireRelationOids(t *testing.T) {
  258. var (
  259. c = context.TODO()
  260. tp = int8(1)
  261. mid = int64(88888894)
  262. )
  263. convey.Convey("ExpireRelationOids", t, func(ctx convey.C) {
  264. ok, err := d.ExpireRelationOids(c, tp, mid)
  265. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  266. ctx.So(err, convey.ShouldBeNil)
  267. ctx.So(ok, convey.ShouldNotBeNil)
  268. })
  269. })
  270. }
  271. func TestFavAddRelationOidCache(t *testing.T) {
  272. var (
  273. c = context.TODO()
  274. tp = int8(1)
  275. mid = int64(88888894)
  276. oid = int64(1)
  277. )
  278. convey.Convey("AddRelationOidCache", t, func(ctx convey.C) {
  279. err := d.AddRelationOidCache(c, tp, mid, oid)
  280. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  281. ctx.So(err, convey.ShouldBeNil)
  282. })
  283. })
  284. }
  285. func TestFavRemRelationOidCache(t *testing.T) {
  286. var (
  287. c = context.TODO()
  288. tp = int8(1)
  289. mid = int64(88888894)
  290. oid = int64(123)
  291. )
  292. convey.Convey("RemRelationOidCache", t, func(ctx convey.C) {
  293. err := d.RemRelationOidCache(c, tp, mid, oid)
  294. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  295. ctx.So(err, convey.ShouldBeNil)
  296. })
  297. })
  298. }
  299. func TestFavIsFavedCache(t *testing.T) {
  300. var (
  301. c = context.TODO()
  302. tp = int8(1)
  303. mid = int64(88888894)
  304. oid = int64(123)
  305. )
  306. convey.Convey("IsFavedCache", t, func(ctx convey.C) {
  307. isFaved, err := d.IsFavedCache(c, tp, mid, oid)
  308. ctx.Convey("Then err should be nil.isFaved should not be nil.", func(ctx convey.C) {
  309. ctx.So(err, convey.ShouldBeNil)
  310. ctx.So(isFaved, convey.ShouldNotBeNil)
  311. })
  312. })
  313. }
  314. func TestFavIsFavedsCache(t *testing.T) {
  315. var (
  316. c = context.TODO()
  317. tp = int8(1)
  318. mid = int64(88888894)
  319. oids = []int64{1, 2, 3}
  320. )
  321. convey.Convey("IsFavedsCache", t, func(ctx convey.C) {
  322. favoreds, err := d.IsFavedsCache(c, tp, mid, oids)
  323. ctx.Convey("Then err should be nil.favoreds should not be nil.", func(ctx convey.C) {
  324. ctx.So(err, convey.ShouldBeNil)
  325. ctx.So(favoreds, convey.ShouldNotBeNil)
  326. })
  327. })
  328. }
  329. func TestFavSetFavedBit(t *testing.T) {
  330. var (
  331. c = context.TODO()
  332. tp = int8(1)
  333. mid = int64(88888894)
  334. )
  335. convey.Convey("SetFavedBit", t, func(ctx convey.C) {
  336. err := d.SetFavedBit(c, tp, mid)
  337. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  338. ctx.So(err, convey.ShouldBeNil)
  339. })
  340. })
  341. }
  342. func TestFavSetUnFavedBit(t *testing.T) {
  343. var (
  344. c = context.TODO()
  345. tp = int8(1)
  346. mid = int64(88888894)
  347. )
  348. convey.Convey("SetUnFavedBit", t, func(ctx convey.C) {
  349. err := d.SetUnFavedBit(c, tp, mid)
  350. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  351. ctx.So(err, convey.ShouldBeNil)
  352. })
  353. })
  354. }
  355. func TestFavFavedBit(t *testing.T) {
  356. var (
  357. c = context.TODO()
  358. tp = int8(1)
  359. mid = int64(88888894)
  360. )
  361. convey.Convey("FavedBit", t, func(ctx convey.C) {
  362. unfaved, err := d.FavedBit(c, tp, mid)
  363. ctx.Convey("Then err should be nil.unfaved should not be nil.", func(ctx convey.C) {
  364. ctx.So(err, convey.ShouldBeNil)
  365. ctx.So(unfaved, convey.ShouldNotBeNil)
  366. })
  367. })
  368. }
  369. func TestFavDelRelationsCache(t *testing.T) {
  370. var (
  371. c = context.TODO()
  372. mid = int64(88888894)
  373. fid = int64(1)
  374. )
  375. convey.Convey("DelRelationsCache", t, func(ctx convey.C) {
  376. err := d.DelRelationsCache(c, mid, fid)
  377. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  378. ctx.So(err, convey.ShouldBeNil)
  379. })
  380. })
  381. }
  382. func TestFavDelAllRelationsCache(t *testing.T) {
  383. var (
  384. c = context.TODO()
  385. mid = int64(88888894)
  386. fid = int64(1)
  387. )
  388. convey.Convey("DelRelationsCache", t, func(ctx convey.C) {
  389. err := d.DelAllRelationsCache(c, mid, fid)
  390. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  391. ctx.So(err, convey.ShouldBeNil)
  392. })
  393. })
  394. }
  395. func TestFavRecentOidsCache(t *testing.T) {
  396. var (
  397. c = context.TODO()
  398. typ = int8(1)
  399. mid = int64(88888894)
  400. fids = []int64{1}
  401. )
  402. convey.Convey("RecentOidsCache", t, func(ctx convey.C) {
  403. rctFidsMap, missFids, err := d.RecentOidsCache(c, typ, mid, fids)
  404. ctx.Convey("Then err should be nil.rctFidsMap,missFids should not be nil.", func(ctx convey.C) {
  405. ctx.So(err, convey.ShouldBeNil)
  406. ctx.So(missFids, convey.ShouldNotBeNil)
  407. ctx.So(rctFidsMap, convey.ShouldNotBeNil)
  408. })
  409. })
  410. }
  411. func TestFavBatchOidsRedis(t *testing.T) {
  412. var (
  413. c = context.TODO()
  414. tp = int8(1)
  415. mid = int64(88888894)
  416. limit = int(10)
  417. )
  418. convey.Convey("BatchOidsRedis", t, func(ctx convey.C) {
  419. oids, err := d.BatchOidsRedis(c, tp, mid, limit)
  420. ctx.Convey("Then err should be nil.oids should not be nil.", func(ctx convey.C) {
  421. ctx.So(err, convey.ShouldBeNil)
  422. ctx.So(oids, convey.ShouldNotBeNil)
  423. })
  424. })
  425. }
  426. func TestIsCleaned(t *testing.T) {
  427. var (
  428. c = context.TODO()
  429. typ = int8(2)
  430. mid = int64(88888894)
  431. fid = int64(59)
  432. )
  433. convey.Convey("IsCleaned", t, func(ctx convey.C) {
  434. _, err := d.IsCleaned(c, typ, mid, fid)
  435. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  436. ctx.So(err, convey.ShouldBeNil)
  437. })
  438. })
  439. }
  440. func TestSetCleanedCache(t *testing.T) {
  441. var (
  442. c = context.TODO()
  443. typ = int8(2)
  444. mid = int64(88888894)
  445. fid = int64(59)
  446. ftime = int64(88888894)
  447. expire = int64(86400)
  448. )
  449. convey.Convey("SetCleanedCache", t, func(ctx convey.C) {
  450. err := d.SetCleanedCache(c, typ, mid, fid, ftime, expire)
  451. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  452. ctx.So(err, convey.ShouldBeNil)
  453. })
  454. })
  455. }