memcache_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/coupon/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoreceiveLogKey(t *testing.T) {
  9. var (
  10. appkey = "123"
  11. orderNo = "456"
  12. ct = int8(0)
  13. )
  14. convey.Convey("TestDaoreceiveLogKey ", t, func(ctx convey.C) {
  15. p1 := receiveLogKey(appkey, orderNo, ct)
  16. ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldEqual, "rl:1234560")
  18. })
  19. })
  20. }
  21. func TestDaoprizeCardKey(t *testing.T) {
  22. var (
  23. mid int64 = 22
  24. actID int64 = 1
  25. ct = int8(0)
  26. )
  27. convey.Convey("TestDaoprizeCardKey ", t, func(ctx convey.C) {
  28. p1 := prizeCardKey(mid, actID, ct)
  29. ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
  30. ctx.So(p1, convey.ShouldEqual, "nypc:22:1:0")
  31. })
  32. })
  33. }
  34. func TestDaoprizeCardsKey(t *testing.T) {
  35. var (
  36. mid int64 = 22
  37. actID int64 = 1
  38. )
  39. convey.Convey("TestDaoprizeCardsKey ", t, func(ctx convey.C) {
  40. p1 := prizeCardsKey(mid, actID)
  41. ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldEqual, "nypcs:22:1")
  43. })
  44. })
  45. }
  46. func TestDaocouponuniqueNoKey(t *testing.T) {
  47. var (
  48. uniqueno string = "uniqueno"
  49. )
  50. convey.Convey("TestDaocouponuniqueNoKey ", t, func(ctx convey.C) {
  51. p1 := couponuniqueNoKey(uniqueno)
  52. ctx.Convey("Then p1 should equal.", func(ctx convey.C) {
  53. ctx.So(p1, convey.ShouldEqual, "uq:uniqueno")
  54. })
  55. })
  56. }
  57. func TestDaocouponsKey(t *testing.T) {
  58. var (
  59. mid = int64(0)
  60. ct = int8(0)
  61. )
  62. convey.Convey("couponsKey ", t, func(ctx convey.C) {
  63. p1 := couponsKey(mid, ct)
  64. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  65. ctx.So(p1, convey.ShouldNotBeNil)
  66. })
  67. })
  68. }
  69. func TestDaouseUniqueKey(t *testing.T) {
  70. var (
  71. orderNO = "1"
  72. ct = int8(0)
  73. )
  74. convey.Convey("useUniqueKey", t, func(ctx convey.C) {
  75. p1 := useUniqueKey(orderNO, ct)
  76. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  77. ctx.So(p1, convey.ShouldNotBeNil)
  78. })
  79. })
  80. }
  81. func TestDaocouponBalancesKey(t *testing.T) {
  82. var (
  83. mid = int64(0)
  84. ct = int8(0)
  85. )
  86. convey.Convey("couponBalancesKey", t, func(ctx convey.C) {
  87. p1 := couponBalancesKey(mid, ct)
  88. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  89. ctx.So(p1, convey.ShouldNotBeNil)
  90. })
  91. })
  92. }
  93. func TestDaouserGrantKey(t *testing.T) {
  94. var (
  95. token = "1"
  96. mid = int64(0)
  97. )
  98. convey.Convey("userGrantKey", t, func(ctx convey.C) {
  99. p1 := userGrantKey(token, mid)
  100. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  101. ctx.So(p1, convey.ShouldNotBeNil)
  102. })
  103. })
  104. }
  105. func TestDaobranchCurrentCount(t *testing.T) {
  106. var (
  107. token = "1"
  108. )
  109. convey.Convey("branchCurrentCount", t, func(ctx convey.C) {
  110. p1 := branchCurrentCount(token)
  111. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  112. ctx.So(p1, convey.ShouldNotBeNil)
  113. })
  114. })
  115. }
  116. func TestDaocouponAllowancesKey(t *testing.T) {
  117. var (
  118. mid = int64(0)
  119. )
  120. convey.Convey("couponAllowancesKey", t, func(ctx convey.C) {
  121. p1 := couponAllowancesKey(mid, 0)
  122. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  123. ctx.So(p1, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoDelUniqueKey(t *testing.T) {
  128. var (
  129. c = context.TODO()
  130. orderNO = "1"
  131. ct = int8(0)
  132. )
  133. convey.Convey("DelUniqueKey", t, func(ctx convey.C) {
  134. err := d.DelUniqueKey(c, orderNO, ct)
  135. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  136. ctx.So(err, convey.ShouldBeNil)
  137. })
  138. })
  139. }
  140. func TestDaoDelCouponsCache(t *testing.T) {
  141. var (
  142. c = context.TODO()
  143. mid = int64(0)
  144. ct = int8(0)
  145. )
  146. convey.Convey("DelCouponsCache", t, func(ctx convey.C) {
  147. err := d.DelCouponsCache(c, mid, ct)
  148. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  149. ctx.So(err, convey.ShouldBeNil)
  150. })
  151. })
  152. }
  153. func TestDaoDelCouponBalancesCache(t *testing.T) {
  154. var (
  155. c = context.TODO()
  156. mid = int64(0)
  157. ct = int8(0)
  158. )
  159. convey.Convey("DelCouponBalancesCache", t, func(ctx convey.C) {
  160. err := d.DelCouponBalancesCache(c, mid, ct)
  161. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. })
  164. })
  165. }
  166. func TestDaoDelGrantKey(t *testing.T) {
  167. var (
  168. c = context.TODO()
  169. token = "1"
  170. mid = int64(0)
  171. )
  172. convey.Convey("DelGrantKey", t, func(ctx convey.C) {
  173. err := d.DelGrantKey(c, token, mid)
  174. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  175. ctx.So(err, convey.ShouldBeNil)
  176. })
  177. })
  178. }
  179. func TestDaoDelBranchCurrentCountKey(t *testing.T) {
  180. var (
  181. c = context.TODO()
  182. token = "1"
  183. )
  184. convey.Convey("DelBranchCurrentCountKey", t, func(ctx convey.C) {
  185. err := d.DelBranchCurrentCountKey(c, token)
  186. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  187. ctx.So(err, convey.ShouldBeNil)
  188. })
  189. })
  190. }
  191. func TestDaoDelCouponAllowancesKey(t *testing.T) {
  192. var (
  193. c = context.Background()
  194. mid = int64(0)
  195. )
  196. convey.Convey("DelCouponAllowancesKey", t, func(ctx convey.C) {
  197. err := d.DelCouponAllowancesKey(c, mid, 0)
  198. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  199. ctx.So(err, convey.ShouldBeNil)
  200. })
  201. })
  202. }
  203. func TestDaoDelPrizeCardKey(t *testing.T) {
  204. var (
  205. c = context.Background()
  206. mid int64 = 22
  207. actID int64 = 1
  208. ct = int8(0)
  209. )
  210. convey.Convey("DelPrizeCardKey", t, func(ctx convey.C) {
  211. err := d.DelPrizeCardKey(c, mid, actID, ct)
  212. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  213. ctx.So(err, convey.ShouldBeNil)
  214. })
  215. })
  216. }
  217. func TestDaoDelPrizeCardsKey(t *testing.T) {
  218. var (
  219. c = context.Background()
  220. mid int64 = 22
  221. actID int64 = 1
  222. )
  223. convey.Convey("DelCouponAllowancesKey", t, func(ctx convey.C) {
  224. err := d.DelPrizeCardsKey(c, mid, actID)
  225. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  226. ctx.So(err, convey.ShouldBeNil)
  227. })
  228. })
  229. }
  230. func TestDaoCouponsCache(t *testing.T) {
  231. var (
  232. c = context.TODO()
  233. mid = int64(0)
  234. ct = int8(0)
  235. coupons = []*model.CouponInfo{}
  236. err error
  237. )
  238. convey.Convey("CouponsCache", t, func(ctx convey.C) {
  239. coupons, err = d.CouponsCache(c, mid, ct)
  240. ctx.Convey("Then err should be nil.coupons should be nil.", func(ctx convey.C) {
  241. ctx.So(err, convey.ShouldBeNil)
  242. ctx.So(coupons, convey.ShouldBeNil)
  243. })
  244. err = d.SetCouponsCache(c, mid, ct, coupons)
  245. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  246. ctx.So(err, convey.ShouldBeNil)
  247. })
  248. coupons, err = d.CouponsCache(c, mid, ct)
  249. ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
  250. ctx.So(err, convey.ShouldBeNil)
  251. ctx.So(coupons, convey.ShouldNotBeNil)
  252. })
  253. })
  254. }
  255. func TestDaoAddUseUniqueLock(t *testing.T) {
  256. var (
  257. c = context.TODO()
  258. orderNO = "1"
  259. ct = int8(0)
  260. )
  261. convey.Convey("AddUseUniqueLock", t, func(ctx convey.C) {
  262. succeed := d.AddUseUniqueLock(c, orderNO, ct)
  263. ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
  264. ctx.So(succeed, convey.ShouldNotBeNil)
  265. })
  266. })
  267. }
  268. func TestDaoAddReceiveUniqueLock(t *testing.T) {
  269. var (
  270. c = context.TODO()
  271. appkey = "1"
  272. orderNO = "2"
  273. ct = int8(0)
  274. )
  275. convey.Convey("AddReceiveUniqueLock", t, func(ctx convey.C) {
  276. succeed := d.AddReceiveUniqueLock(c, appkey, orderNO, ct)
  277. ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
  278. ctx.So(succeed, convey.ShouldNotBeNil)
  279. })
  280. })
  281. }
  282. func TestDaoDelReceiveUniqueLock(t *testing.T) {
  283. var (
  284. c = context.TODO()
  285. appkey = "1"
  286. orderNO = "1"
  287. ct = int8(0)
  288. )
  289. convey.Convey("DelReceiveUniqueLock ", t, func(ctx convey.C) {
  290. err := d.DelReceiveUniqueLock(c, appkey, orderNO, ct)
  291. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  292. ctx.So(err, convey.ShouldBeNil)
  293. })
  294. })
  295. }
  296. func TestDaodelCache(t *testing.T) {
  297. var (
  298. c = context.TODO()
  299. key = "1"
  300. )
  301. convey.Convey("delCache", t, func(ctx convey.C) {
  302. err := d.delCache(c, key)
  303. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  304. ctx.So(err, convey.ShouldBeNil)
  305. })
  306. })
  307. }
  308. func TestDaoCouponBlanceCache(t *testing.T) {
  309. var (
  310. c = context.TODO()
  311. mid = int64(0)
  312. ct = int8(0)
  313. coupons = []*model.CouponBalanceInfo{}
  314. )
  315. convey.Convey("CouponBlanceCache", t, func(ctx convey.C) {
  316. err := d.SetCouponBlanceCache(c, mid, ct, coupons)
  317. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  318. ctx.So(err, convey.ShouldBeNil)
  319. })
  320. coupons, err := d.CouponBlanceCache(c, mid, ct)
  321. ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
  322. ctx.So(err, convey.ShouldBeNil)
  323. ctx.So(coupons, convey.ShouldNotBeNil)
  324. })
  325. })
  326. }
  327. func TestDaoAddUniqueNoLock(t *testing.T) {
  328. var (
  329. c = context.TODO()
  330. uniqueno = "1"
  331. )
  332. convey.Convey("AddUniqueNoLock", t, func(ctx convey.C) {
  333. succeed := d.AddUniqueNoLock(c, uniqueno)
  334. ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
  335. ctx.So(succeed, convey.ShouldNotBeNil)
  336. })
  337. })
  338. }
  339. func TestDaoAddGrantUniqueLock(t *testing.T) {
  340. var (
  341. c = context.TODO()
  342. token = "1"
  343. mid = int64(0)
  344. )
  345. convey.Convey("AddGrantUniqueLock", t, func(ctx convey.C) {
  346. succeed := d.AddGrantUniqueLock(c, token, mid)
  347. ctx.Convey("Then succeed should not be nil.", func(ctx convey.C) {
  348. ctx.So(succeed, convey.ShouldNotBeNil)
  349. })
  350. })
  351. }
  352. func TestDaoBranchCurrentCountCache(t *testing.T) {
  353. var (
  354. c = context.TODO()
  355. token = "1"
  356. )
  357. convey.Convey("BranchCurrentCountCache", t, func(ctx convey.C) {
  358. count, err := d.BranchCurrentCountCache(c, token)
  359. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  360. ctx.So(err, convey.ShouldBeNil)
  361. ctx.So(count, convey.ShouldNotBeNil)
  362. })
  363. })
  364. }
  365. func TestDaoSetBranchCurrentCountCache(t *testing.T) {
  366. var (
  367. c = context.TODO()
  368. token = "1"
  369. count = int(0)
  370. )
  371. convey.Convey("SetBranchCurrentCountCache", t, func(ctx convey.C) {
  372. err := d.SetBranchCurrentCountCache(c, token, count)
  373. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  374. ctx.So(err, convey.ShouldBeNil)
  375. })
  376. })
  377. }
  378. func TestDaoIncreaseBranchCurrentCountCache(t *testing.T) {
  379. var (
  380. c = context.TODO()
  381. token = "1"
  382. count = uint64(0)
  383. )
  384. convey.Convey("IncreaseBranchCurrentCountCache", t, func(ctx convey.C) {
  385. err := d.IncreaseBranchCurrentCountCache(c, token, count)
  386. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  387. ctx.So(err, convey.ShouldBeNil)
  388. })
  389. })
  390. }
  391. func TestDaoCouponAllowanceCache(t *testing.T) {
  392. var (
  393. c = context.TODO()
  394. mid = int64(0)
  395. coupons = []*model.CouponAllowanceInfo{}
  396. )
  397. convey.Convey("CouponAllowanceCache", t, func(ctx convey.C) {
  398. err := d.SetCouponAllowanceCache(c, mid, 0, coupons)
  399. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  400. ctx.So(err, convey.ShouldBeNil)
  401. })
  402. coupons, err := d.CouponAllowanceCache(c, mid, 0)
  403. ctx.Convey("Then err should be nil.coupons should not be nil.", func(ctx convey.C) {
  404. ctx.So(err, convey.ShouldBeNil)
  405. ctx.So(coupons, convey.ShouldNotBeNil)
  406. })
  407. })
  408. }
  409. func TestDaoSetPrizeCardCache(t *testing.T) {
  410. var (
  411. c = context.TODO()
  412. mid int64 = 1
  413. actID int64 = 1
  414. prizeCard = &model.PrizeCardRep{}
  415. )
  416. convey.Convey("SetPrizeCardCache ", t, func(ctx convey.C) {
  417. err := d.SetPrizeCardCache(c, mid, actID, prizeCard)
  418. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  419. ctx.So(err, convey.ShouldBeNil)
  420. })
  421. })
  422. }
  423. func TestDaoSetPrizeCardsCache(t *testing.T) {
  424. var (
  425. c = context.TODO()
  426. mid = int64(1)
  427. actID = int64(1)
  428. prizeCards = make([]*model.PrizeCardRep, 0)
  429. prizeCard = &model.PrizeCardRep{}
  430. )
  431. prizeCards = append(prizeCards, prizeCard)
  432. convey.Convey("SetPrizeCardsCache ", t, func(ctx convey.C) {
  433. err := d.SetPrizeCardsCache(c, mid, actID, prizeCards)
  434. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  435. ctx.So(err, convey.ShouldBeNil)
  436. })
  437. })
  438. }
  439. func TestDaoPrizeCardCache(t *testing.T) {
  440. var (
  441. c = context.TODO()
  442. mid = int64(1)
  443. actID = int64(1)
  444. ct = int8(0)
  445. prizeCard = &model.PrizeCardRep{}
  446. )
  447. convey.Convey("PrizeCardCache", t, func(ctx convey.C) {
  448. d.SetPrizeCardCache(c, mid, actID, prizeCard)
  449. res, err := d.PrizeCardCache(c, mid, actID, ct)
  450. ctx.Convey("Then err should be nil.res should be not nil.", func(ctx convey.C) {
  451. ctx.So(err, convey.ShouldBeNil)
  452. ctx.So(res, convey.ShouldNotBeNil)
  453. })
  454. d.DelPrizeCardKey(c, mid, actID, ct)
  455. res, err = d.PrizeCardCache(c, mid, actID, ct)
  456. ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
  457. ctx.So(err, convey.ShouldBeNil)
  458. ctx.So(res, convey.ShouldBeNil)
  459. })
  460. })
  461. }
  462. func TestDaoPrizeCardsCache(t *testing.T) {
  463. var (
  464. c = context.TODO()
  465. mid = int64(1)
  466. actID = int64(1)
  467. prizeCards = make([]*model.PrizeCardRep, 0)
  468. prizeCard = &model.PrizeCardRep{}
  469. )
  470. prizeCards = append(prizeCards, prizeCard)
  471. convey.Convey("PrizeCardCache", t, func(ctx convey.C) {
  472. d.SetPrizeCardsCache(c, mid, actID, prizeCards)
  473. res, err := d.PrizeCardsCache(c, mid, actID)
  474. ctx.Convey("Then err should be nil.res should be not nil.", func(ctx convey.C) {
  475. ctx.So(err, convey.ShouldBeNil)
  476. ctx.So(res, convey.ShouldNotBeNil)
  477. })
  478. d.DelPrizeCardsKey(c, mid, actID)
  479. res, err = d.PrizeCardsCache(c, mid, actID)
  480. ctx.Convey("Then err should be nil.res should be nil.", func(ctx convey.C) {
  481. ctx.So(err, convey.ShouldBeNil)
  482. ctx.So(res, convey.ShouldBeNil)
  483. })
  484. })
  485. }