redis_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. package dao
  2. import (
  3. "context"
  4. v1pb "go-common/app/service/live/gift/api/grpc/v1"
  5. "go-common/app/service/live/gift/model"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaodailyBagKey(t *testing.T) {
  10. convey.Convey("dailyBagKey", t, func(c convey.C) {
  11. var (
  12. uid = int64(0)
  13. )
  14. c.Convey("When everything gose positive", func(c convey.C) {
  15. p1 := dailyBagKey(uid)
  16. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  17. c.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDaoGetDailyBagCache(t *testing.T) {
  23. convey.Convey("GetDailyBagCache", t, func(c convey.C) {
  24. var (
  25. ctx = context.Background()
  26. uid = int64(0)
  27. )
  28. c.Convey("When everything gose positive", func(c convey.C) {
  29. res, err := d.GetDailyBagCache(ctx, uid)
  30. c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
  31. c.So(err, convey.ShouldBeNil)
  32. c.So(res, convey.ShouldBeNil)
  33. })
  34. })
  35. })
  36. }
  37. func TestDaoSetDailyBagCache(t *testing.T) {
  38. convey.Convey("SetDailyBagCache", t, func(c convey.C) {
  39. var (
  40. ctx = context.Background()
  41. uid = int64(9527)
  42. data = []*v1pb.DailyBagResp_BagList{}
  43. expire = int64(1)
  44. )
  45. c.Convey("When everything gose positive", func(c convey.C) {
  46. err := d.SetDailyBagCache(ctx, uid, data, expire)
  47. c.Convey("Then err should be nil.", func(c convey.C) {
  48. c.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaodailyMedalBagKey(t *testing.T) {
  54. convey.Convey("dailyMedalBagKey", t, func(c convey.C) {
  55. var (
  56. uid = int64(0)
  57. )
  58. c.Convey("When everything gose positive", func(c convey.C) {
  59. p1 := dailyMedalBagKey(uid)
  60. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  61. c.So(p1, convey.ShouldNotBeNil)
  62. })
  63. })
  64. })
  65. }
  66. func TestDaoGetMedalDailyBagCache(t *testing.T) {
  67. convey.Convey("GetMedalDailyBagCache", t, func(c convey.C) {
  68. var (
  69. ctx = context.Background()
  70. uid = int64(-1)
  71. )
  72. c.Convey("When everything gose positive", func(c convey.C) {
  73. res, err := d.GetMedalDailyBagCache(ctx, uid)
  74. c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
  75. c.So(err, convey.ShouldBeNil)
  76. c.So(res, convey.ShouldBeNil)
  77. })
  78. })
  79. })
  80. }
  81. func TestDaoSetMedalDailyBagCache(t *testing.T) {
  82. convey.Convey("SetMedalDailyBagCache", t, func(c convey.C) {
  83. var (
  84. ctx = context.Background()
  85. uid = int64(9527)
  86. data = &model.BagGiftStatus{}
  87. expire = int64(1)
  88. )
  89. c.Convey("When everything gose positive", func(c convey.C) {
  90. err := d.SetMedalDailyBagCache(ctx, uid, data, expire)
  91. c.Convey("Then err should be nil.", func(c convey.C) {
  92. c.So(err, convey.ShouldBeNil)
  93. })
  94. })
  95. })
  96. }
  97. func TestDaoweekLevelBagKey(t *testing.T) {
  98. convey.Convey("weekLevelBagKey", t, func(c convey.C) {
  99. var (
  100. uid = int64(0)
  101. level = int64(0)
  102. )
  103. c.Convey("When everything gose positive", func(c convey.C) {
  104. p1 := weekLevelBagKey(uid, level)
  105. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  106. c.So(p1, convey.ShouldNotBeNil)
  107. })
  108. })
  109. })
  110. }
  111. func TestDaoGetWeekLevelBagCache(t *testing.T) {
  112. convey.Convey("GetWeekLevelBagCache", t, func(c convey.C) {
  113. var (
  114. ctx = context.Background()
  115. uid = int64(-1)
  116. level = int64(1)
  117. )
  118. c.Convey("When everything gose positive", func(c convey.C) {
  119. res, err := d.GetWeekLevelBagCache(ctx, uid, level)
  120. c.Convey("Then err should be nil.res should not be nil.", func(c convey.C) {
  121. c.So(err, convey.ShouldBeNil)
  122. c.So(res, convey.ShouldBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestDaoSetWeekLevelBagCache(t *testing.T) {
  128. convey.Convey("SetWeekLevelBagCache", t, func(c convey.C) {
  129. var (
  130. ctx = context.Background()
  131. uid = int64(9527)
  132. level = int64(0)
  133. data = &model.BagGiftStatus{}
  134. expire = int64(1)
  135. )
  136. c.Convey("When everything gose positive", func(c convey.C) {
  137. err := d.SetWeekLevelBagCache(ctx, uid, level, data, expire)
  138. c.Convey("Then err should be nil.", func(c convey.C) {
  139. c.So(err, convey.ShouldBeNil)
  140. })
  141. })
  142. })
  143. }
  144. func TestDaoLock(t *testing.T) {
  145. convey.Convey("Lock", t, func(c convey.C) {
  146. var (
  147. ctx = context.Background()
  148. key = "test lock"
  149. ttl = int(1)
  150. retry = int(0)
  151. retryDelay = int(0)
  152. )
  153. c.Convey("When everything gose positive", func(c convey.C) {
  154. gotLock, lockValue, err := d.Lock(ctx, key, ttl, retry, retryDelay)
  155. c.Convey("Then err should be nil.gotLock,lockValue should not be nil.", func(c convey.C) {
  156. c.So(lockValue, convey.ShouldNotBeNil)
  157. c.So(err, convey.ShouldBeNil)
  158. c.So(gotLock, convey.ShouldNotBeNil)
  159. })
  160. })
  161. })
  162. }
  163. func TestDaoUnLock(t *testing.T) {
  164. convey.Convey("UnLock", t, func(c convey.C) {
  165. var (
  166. ctx = context.Background()
  167. key = "test unlock"
  168. lockValue = "1"
  169. )
  170. c.Convey("When everything gose positive", func(c convey.C) {
  171. err := d.UnLock(ctx, key, lockValue)
  172. c.Convey("Then err should be nil.", func(c convey.C) {
  173. c.So(err, convey.ShouldBeNil)
  174. })
  175. })
  176. })
  177. }
  178. func TestDaoForceUnLock(t *testing.T) {
  179. convey.Convey("ForceUnLock", t, func(c convey.C) {
  180. var (
  181. ctx = context.Background()
  182. key = ""
  183. )
  184. c.Convey("When everything gose positive", func(c convey.C) {
  185. err := d.ForceUnLock(ctx, key)
  186. c.Convey("Then err should be nil.", func(c convey.C) {
  187. c.So(err, convey.ShouldBeNil)
  188. })
  189. })
  190. })
  191. }
  192. func TestDaolockKey(t *testing.T) {
  193. convey.Convey("lockKey", t, func(c convey.C) {
  194. var (
  195. key = ""
  196. )
  197. c.Convey("When everything gose positive", func(c convey.C) {
  198. p1 := lockKey(key)
  199. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  200. c.So(p1, convey.ShouldNotBeNil)
  201. })
  202. })
  203. })
  204. }
  205. func TestDaorandomString(t *testing.T) {
  206. convey.Convey("randomString", t, func(c convey.C) {
  207. var (
  208. l = int(0)
  209. )
  210. c.Convey("When everything gose positive", func(c convey.C) {
  211. p1 := randomString(l)
  212. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  213. c.So(p1, convey.ShouldNotBeNil)
  214. })
  215. })
  216. })
  217. }
  218. func TestDaobagIDCache(t *testing.T) {
  219. convey.Convey("bagIDCache", t, func(c convey.C) {
  220. var (
  221. uid = int64(0)
  222. giftID = int64(0)
  223. expireAt = int64(0)
  224. )
  225. c.Convey("When everything gose positive", func(c convey.C) {
  226. p1 := bagIDCache(uid, giftID, expireAt)
  227. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  228. c.So(p1, convey.ShouldNotBeNil)
  229. })
  230. })
  231. })
  232. }
  233. func TestDaoGetBagIDCache(t *testing.T) {
  234. convey.Convey("GetBagIDCache", t, func(c convey.C) {
  235. var (
  236. ctx = context.Background()
  237. uid = int64(0)
  238. giftID = int64(0)
  239. expireAt = int64(0)
  240. )
  241. c.Convey("When everything gose positive", func(c convey.C) {
  242. bagID, err := d.GetBagIDCache(ctx, uid, giftID, expireAt)
  243. c.Convey("Then err should be nil.bagID should not be nil.", func(c convey.C) {
  244. c.So(err, convey.ShouldBeNil)
  245. c.So(bagID, convey.ShouldNotBeNil)
  246. })
  247. })
  248. })
  249. }
  250. func TestDaoSetBagIDCache(t *testing.T) {
  251. convey.Convey("SetBagIDCache", t, func(c convey.C) {
  252. var (
  253. ctx = context.Background()
  254. uid = int64(9527)
  255. giftID = int64(1)
  256. expireAt = int64(1)
  257. bagID = int64(1)
  258. expire = int64(1)
  259. )
  260. c.Convey("When everything gose positive", func(c convey.C) {
  261. err := d.SetBagIDCache(ctx, uid, giftID, expireAt, bagID, expire)
  262. c.Convey("Then err should be nil.", func(c convey.C) {
  263. c.So(err, convey.ShouldBeNil)
  264. })
  265. })
  266. })
  267. }
  268. func TestDaobagListKey(t *testing.T) {
  269. convey.Convey("bagListKey", t, func(c convey.C) {
  270. var (
  271. uid = int64(0)
  272. )
  273. c.Convey("When everything gose positive", func(c convey.C) {
  274. p1 := bagListKey(uid)
  275. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  276. c.So(p1, convey.ShouldNotBeNil)
  277. })
  278. })
  279. })
  280. }
  281. func TestDaoGetBagListCache(t *testing.T) {
  282. convey.Convey("GetBagListCache", t, func(c convey.C) {
  283. var (
  284. ctx = context.Background()
  285. uid = int64(0)
  286. )
  287. c.Convey("When everything gose positive", func(c convey.C) {
  288. res, err := d.GetBagListCache(ctx, uid)
  289. c.Convey("Then err should be nil.res should be nil.", func(c convey.C) {
  290. c.So(err, convey.ShouldBeNil)
  291. c.So(res, convey.ShouldBeNil)
  292. })
  293. })
  294. })
  295. }
  296. func TestDaoSetBagListCache(t *testing.T) {
  297. convey.Convey("SetBagListCache", t, func(c convey.C) {
  298. var (
  299. ctx = context.Background()
  300. uid = int64(0)
  301. data = []*model.BagGiftList{}
  302. expire = int64(1)
  303. )
  304. c.Convey("When everything gose positive", func(c convey.C) {
  305. err := d.SetBagListCache(ctx, uid, data, expire)
  306. c.Convey("Then err should be nil.", func(c convey.C) {
  307. c.So(err, convey.ShouldBeNil)
  308. })
  309. })
  310. })
  311. }
  312. func TestDaoClearBagListCache(t *testing.T) {
  313. convey.Convey("ClearBagListCache", t, func(c convey.C) {
  314. var (
  315. ctx = context.Background()
  316. uid = int64(0)
  317. )
  318. c.Convey("When everything gose positive", func(c convey.C) {
  319. err := d.ClearBagListCache(ctx, uid)
  320. c.Convey("Then err should be nil.", func(c convey.C) {
  321. c.So(err, convey.ShouldBeNil)
  322. })
  323. })
  324. })
  325. }
  326. func TestDaobagNumKey(t *testing.T) {
  327. convey.Convey("bagNumKey", t, func(c convey.C) {
  328. var (
  329. uid = int64(0)
  330. giftID = int64(0)
  331. expireAt = int64(0)
  332. )
  333. c.Convey("When everything gose positive", func(c convey.C) {
  334. p1 := bagNumKey(uid, giftID, expireAt)
  335. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  336. c.So(p1, convey.ShouldNotBeNil)
  337. })
  338. })
  339. })
  340. }
  341. func TestDaoSetBagNumCache(t *testing.T) {
  342. convey.Convey("SetBagNumCache", t, func(c convey.C) {
  343. var (
  344. ctx = context.Background()
  345. uid = int64(9527)
  346. giftID = int64(1)
  347. expireAt = int64(1)
  348. giftNum = int64(1)
  349. expire = int64(1)
  350. )
  351. c.Convey("When everything gose positive", func(c convey.C) {
  352. err := d.SetBagNumCache(ctx, uid, giftID, expireAt, giftNum, expire)
  353. c.Convey("Then err should be nil.", func(c convey.C) {
  354. c.So(err, convey.ShouldBeNil)
  355. })
  356. })
  357. })
  358. }
  359. func TestDaovipMonthBag(t *testing.T) {
  360. convey.Convey("vipMonthBag", t, func(c convey.C) {
  361. var (
  362. uid = int64(0)
  363. )
  364. c.Convey("When everything gose positive", func(c convey.C) {
  365. p1 := vipMonthBag(uid)
  366. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  367. c.So(p1, convey.ShouldNotBeNil)
  368. })
  369. })
  370. })
  371. }
  372. func TestDaoGetVipStatusCache(t *testing.T) {
  373. convey.Convey("GetVipStatusCache", t, func(c convey.C) {
  374. var (
  375. ctx = context.Background()
  376. uid = int64(0)
  377. )
  378. c.Convey("When everything gose positive", func(c convey.C) {
  379. status, err := d.GetVipStatusCache(ctx, uid)
  380. c.Convey("Then err should be nil.status should not be nil.", func(c convey.C) {
  381. c.So(err, convey.ShouldBeNil)
  382. c.So(status, convey.ShouldNotBeNil)
  383. })
  384. })
  385. })
  386. }
  387. func TestDaoClearVipStatusCache(t *testing.T) {
  388. convey.Convey("ClearVipStatusCache", t, func(c convey.C) {
  389. var (
  390. ctx = context.Background()
  391. uid = int64(0)
  392. )
  393. c.Convey("When everything gose positive", func(c convey.C) {
  394. err := d.ClearVipStatusCache(ctx, uid)
  395. c.Convey("Then err should be nil.", func(c convey.C) {
  396. c.So(err, convey.ShouldBeNil)
  397. })
  398. })
  399. })
  400. }
  401. func TestDaogiftBagStatus(t *testing.T) {
  402. convey.Convey("giftBagStatus", t, func(c convey.C) {
  403. var (
  404. uid = int64(0)
  405. )
  406. c.Convey("When everything gose positive", func(c convey.C) {
  407. p1 := giftBagStatus(uid)
  408. c.Convey("Then p1 should not be nil.", func(c convey.C) {
  409. c.So(p1, convey.ShouldNotBeNil)
  410. })
  411. })
  412. })
  413. }
  414. func TestDaoGetBagStatusCache(t *testing.T) {
  415. convey.Convey("GetBagStatusCache", t, func(c convey.C) {
  416. var (
  417. ctx = context.Background()
  418. uid = int64(0)
  419. )
  420. c.Convey("When everything gose positive", func(c convey.C) {
  421. status, err := d.GetBagStatusCache(ctx, uid)
  422. c.Convey("Then err should be nil.status should not be nil.", func(c convey.C) {
  423. c.So(err, convey.ShouldBeNil)
  424. c.So(status, convey.ShouldNotBeNil)
  425. })
  426. })
  427. })
  428. }
  429. func TestDaoSetBagStatusCache(t *testing.T) {
  430. convey.Convey("SetBagStatusCache", t, func(c convey.C) {
  431. var (
  432. ctx = context.Background()
  433. uid = int64(9527)
  434. status = int64(1)
  435. expire = int64(1)
  436. )
  437. c.Convey("When everything gose positive", func(c convey.C) {
  438. err := d.SetBagStatusCache(ctx, uid, status, expire)
  439. c.Convey("Then err should be nil.", func(c convey.C) {
  440. c.So(err, convey.ShouldBeNil)
  441. })
  442. })
  443. })
  444. }