redis_test.go 11 KB

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