memcache_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. package dao
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. "github.com/bouk/monkey"
  7. "go-common/app/service/main/member/model"
  8. "go-common/library/cache/memcache"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestDaoexpKey(t *testing.T) {
  12. var (
  13. mid = int64(111001740)
  14. )
  15. convey.Convey("expKey", t, func(ctx convey.C) {
  16. p1 := expKey(mid)
  17. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  18. ctx.So(p1, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestDaomoralKey(t *testing.T) {
  23. var (
  24. mid = int64(111001740)
  25. )
  26. convey.Convey("moralKey", t, func(ctx convey.C) {
  27. p1 := moralKey(mid)
  28. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. }
  33. func TestDaopingMC(t *testing.T) {
  34. var (
  35. c = context.Background()
  36. )
  37. convey.Convey("pingMC", t, func(ctx convey.C) {
  38. err := d.pingMC(c)
  39. ctx.Convey("Error should be nil", func(ctx convey.C) {
  40. ctx.So(err, convey.ShouldBeNil)
  41. })
  42. })
  43. }
  44. func TestDaoSetBaseInfoCache(t *testing.T) {
  45. var (
  46. c = context.Background()
  47. mid = int64(19476037)
  48. info = &model.BaseInfo{
  49. Mid: 19476037,
  50. Name: "lala",
  51. Sign: "We are the world!",
  52. }
  53. )
  54. convey.Convey("SetBaseInfoCache", t, func(ctx convey.C) {
  55. err := d.SetBaseInfoCache(c, mid, info)
  56. ctx.Convey("Error should be nil", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. })
  59. })
  60. }
  61. func TestDaoBaseInfoCache(t *testing.T) {
  62. convey.Convey("BaseInfoCache", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. mid = int64(19476037)
  66. )
  67. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  68. info, err := d.BaseInfoCache(c, mid)
  69. ctx.Convey("Error should be nil. info should not be nil", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(info, convey.ShouldNotBeNil)
  72. })
  73. })
  74. ctx.Convey("When conn.Get gets error", func(ctx convey.C) {
  75. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.mc), "Get", func(_ *memcache.Pool,
  76. _ context.Context) memcache.Conn {
  77. return memcache.MockWith(memcache.ErrItemObject)
  78. })
  79. defer guard.Unpatch()
  80. _, err := d.BaseInfoCache(c, mid)
  81. ctx.Convey("Error should be equal to memcache.ErrItemObject", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldEqual, memcache.ErrItemObject)
  83. })
  84. })
  85. })
  86. }
  87. func TestDaoSetBatchBaseInfoCache(t *testing.T) {
  88. var (
  89. c = context.Background()
  90. bi1 = &model.BaseInfo{
  91. Mid: 19476037,
  92. Name: "lala",
  93. Sign: "We are the world!",
  94. }
  95. bi2 = &model.BaseInfo{
  96. Mid: 4780461,
  97. Name: "lala",
  98. Sign: "We are the world!",
  99. }
  100. bs = []*model.BaseInfo{bi1, bi2}
  101. )
  102. convey.Convey("SetBatchBaseInfoCache", t, func(ctx convey.C) {
  103. err := d.SetBatchBaseInfoCache(c, bs)
  104. ctx.Convey("Error should be nil", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. }
  109. func TestDaoBatchBaseInfoCache(t *testing.T) {
  110. var (
  111. c = context.Background()
  112. mids = []int64{19476037, 1}
  113. )
  114. convey.Convey("BatchBaseInfoCache", t, func(ctx convey.C) {
  115. cached, missed, err := d.BatchBaseInfoCache(c, mids)
  116. ctx.Convey("Error should be nil", func(ctx convey.C) {
  117. ctx.So(err, convey.ShouldBeNil)
  118. })
  119. ctx.Convey("missed should not be nil", func(ctx convey.C) {
  120. ctx.So(missed, convey.ShouldNotBeNil)
  121. })
  122. ctx.Convey("cached should not be nil", func(ctx convey.C) {
  123. ctx.So(cached, convey.ShouldNotBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoDelBaseInfoCache(t *testing.T) {
  128. var (
  129. c = context.Background()
  130. mid = int64(19476037)
  131. )
  132. convey.Convey("DelBaseInfoCache", t, func(ctx convey.C) {
  133. err := d.DelBaseInfoCache(c, mid)
  134. ctx.Convey("Error should be nil", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. })
  137. })
  138. }
  139. func TestDaoSetExpCache(t *testing.T) {
  140. var (
  141. c = context.Background()
  142. mid = int64(19476037)
  143. exp = int64(10)
  144. )
  145. convey.Convey("SetExpCache", t, func(ctx convey.C) {
  146. err := d.SetExpCache(c, mid, exp)
  147. ctx.Convey("Error should be nil", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. })
  150. })
  151. }
  152. func TestDaoexpCache(t *testing.T) {
  153. var (
  154. c = context.Background()
  155. mid = int64(19476037)
  156. )
  157. convey.Convey("expCache", t, func(ctx convey.C) {
  158. exp, err := d.expCache(c, mid)
  159. ctx.Convey("Error should be nil", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. })
  162. ctx.Convey("exp should not be nil", func(ctx convey.C) {
  163. ctx.So(exp, convey.ShouldNotBeNil)
  164. })
  165. })
  166. }
  167. func TestDaoexpsCache(t *testing.T) {
  168. var (
  169. c = context.Background()
  170. mids = []int64{19476037, 4780461}
  171. )
  172. convey.Convey("expsCache", t, func(ctx convey.C) {
  173. exps, miss, err := d.expsCache(c, mids)
  174. ctx.Convey("Error should be nil", func(ctx convey.C) {
  175. ctx.So(err, convey.ShouldBeNil)
  176. })
  177. ctx.Convey("miss should not be nil", func(ctx convey.C) {
  178. ctx.So(miss, convey.ShouldBeNil)
  179. })
  180. ctx.Convey("exps should not be nil", func(ctx convey.C) {
  181. ctx.So(exps, convey.ShouldNotBeNil)
  182. })
  183. })
  184. }
  185. func TestDaoSetMoralCache(t *testing.T) {
  186. var (
  187. c = context.Background()
  188. mid = int64(19476037)
  189. moral = &model.Moral{}
  190. )
  191. convey.Convey("SetMoralCache", t, func(ctx convey.C) {
  192. err := d.SetMoralCache(c, mid, moral)
  193. ctx.Convey("Error should be nil", func(ctx convey.C) {
  194. ctx.So(err, convey.ShouldBeNil)
  195. })
  196. })
  197. }
  198. func TestDaomoralCache(t *testing.T) {
  199. var (
  200. c = context.Background()
  201. mid = int64(19476037)
  202. )
  203. convey.Convey("moralCache", t, func(ctx convey.C) {
  204. moral, err := d.moralCache(c, mid)
  205. ctx.Convey("Error should be nil", func(ctx convey.C) {
  206. ctx.So(err, convey.ShouldBeNil)
  207. })
  208. ctx.Convey("moral should not be nil", func(ctx convey.C) {
  209. ctx.So(moral, convey.ShouldNotBeNil)
  210. })
  211. })
  212. }
  213. func TestDaoDelMoralCache(t *testing.T) {
  214. var (
  215. c = context.Background()
  216. mid = int64(19476037)
  217. )
  218. convey.Convey("DelMoralCache", t, func(ctx convey.C) {
  219. err := d.DelMoralCache(c, mid)
  220. ctx.Convey("Error should be nil", func(ctx convey.C) {
  221. ctx.So(err, convey.ShouldBeNil)
  222. })
  223. })
  224. }
  225. func TestDaorealnameInfoKey(t *testing.T) {
  226. var (
  227. mid = int64(19476037)
  228. )
  229. convey.Convey("realnameApplyKey", t, func(ctx convey.C) {
  230. key := realnameInfoKey(mid)
  231. ctx.Convey("p1 should equal realname_info_<mid>", func(ctx convey.C) {
  232. ctx.So(key, convey.ShouldEqual, "realname_info_19476037")
  233. })
  234. })
  235. }
  236. func TestDaorealnameCaptureTimesKey(t *testing.T) {
  237. var (
  238. mid = int64(19476037)
  239. )
  240. convey.Convey("realnameCaptureTimesKey", t, func(ctx convey.C) {
  241. p1 := realnameCaptureTimesKey(mid)
  242. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  243. ctx.So(p1, convey.ShouldNotBeNil)
  244. })
  245. })
  246. }
  247. func TestDaorealnameCaptureCodeKey(t *testing.T) {
  248. var (
  249. mid = int64(19476037)
  250. )
  251. convey.Convey("realnameCaptureCodeKey", t, func(ctx convey.C) {
  252. p1 := realnameCaptureCodeKey(mid)
  253. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  254. ctx.So(p1, convey.ShouldNotBeNil)
  255. })
  256. })
  257. }
  258. func TestDaorealnameCaptureErrTimesKey(t *testing.T) {
  259. var (
  260. mid = int64(19476037)
  261. )
  262. convey.Convey("realnameCaptureErrTimesKey", t, func(ctx convey.C) {
  263. p1 := realnameCaptureErrTimesKey(mid)
  264. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  265. ctx.So(p1, convey.ShouldNotBeNil)
  266. })
  267. })
  268. }
  269. func TestDaoSetRealnameCaptureTimes(t *testing.T) {
  270. var (
  271. c = context.Background()
  272. mid = int64(19476037)
  273. times = int(0)
  274. )
  275. convey.Convey("SetRealnameCaptureTimes", t, func(ctx convey.C) {
  276. err := d.SetRealnameCaptureTimes(c, mid, times)
  277. ctx.Convey("Error should be nil", func(ctx convey.C) {
  278. ctx.So(err, convey.ShouldBeNil)
  279. })
  280. })
  281. }
  282. func TestDaoRealnameCaptureTimesCache(t *testing.T) {
  283. var (
  284. c = context.Background()
  285. mid = int64(19476037)
  286. )
  287. convey.Convey("RealnameCaptureTimesCache", t, func(ctx convey.C) {
  288. times, err := d.RealnameCaptureTimesCache(c, mid)
  289. ctx.Convey("Error should be nil", func(ctx convey.C) {
  290. ctx.So(err, convey.ShouldBeNil)
  291. })
  292. ctx.Convey("times should not be nil", func(ctx convey.C) {
  293. ctx.So(times, convey.ShouldNotBeNil)
  294. })
  295. })
  296. }
  297. func TestDaoIncreaseRealnameCaptureTimes(t *testing.T) {
  298. var (
  299. c = context.Background()
  300. mid = int64(19476037)
  301. )
  302. convey.Convey("IncreaseRealnameCaptureTimes", t, func(ctx convey.C) {
  303. err := d.IncreaseRealnameCaptureTimes(c, mid)
  304. ctx.Convey("Error should be nil", func(ctx convey.C) {
  305. ctx.So(err, convey.ShouldBeNil)
  306. })
  307. })
  308. }
  309. func TestDaoRealnameCaptureCodeCache(t *testing.T) {
  310. var (
  311. c = context.Background()
  312. mid = int64(19476037)
  313. )
  314. convey.Convey("RealnameCaptureCodeCache", t, func(ctx convey.C) {
  315. code, err := d.RealnameCaptureCodeCache(c, mid)
  316. ctx.Convey("Error should be nil", func(ctx convey.C) {
  317. ctx.So(err, convey.ShouldBeNil)
  318. })
  319. ctx.Convey("code should not be nil", func(ctx convey.C) {
  320. ctx.So(code, convey.ShouldNotBeNil)
  321. })
  322. })
  323. }
  324. func TestDaoSetRealnameInfo(t *testing.T) {
  325. var (
  326. c = context.Background()
  327. mid = int64(19476037)
  328. info = &model.RealnameCacheInfo{}
  329. )
  330. convey.Convey("SetRealnameApplyInfo", t, func(ctx convey.C) {
  331. err := d.SetRealnameInfo(c, mid, info)
  332. ctx.Convey("Error should be nil", func(ctx convey.C) {
  333. ctx.So(err, convey.ShouldBeNil)
  334. })
  335. })
  336. }
  337. func TestDaoRealnameInfoCache(t *testing.T) {
  338. var (
  339. c = context.Background()
  340. mid = int64(19476037)
  341. )
  342. convey.Convey("RealnameApplyInfoCache", t, func(ctx convey.C) {
  343. info, err := d.RealnameInfoCache(c, mid)
  344. ctx.Convey("Error should be nil", func(ctx convey.C) {
  345. ctx.So(err, convey.ShouldBeNil)
  346. })
  347. ctx.Convey("info should not be nil", func(ctx convey.C) {
  348. ctx.So(info, convey.ShouldNotBeNil)
  349. })
  350. })
  351. }
  352. func TestDaoDeleteRealnameInfo(t *testing.T) {
  353. var (
  354. c = context.Background()
  355. mid = int64(19476037)
  356. )
  357. convey.Convey("DeleteRealnameApplyInfo", t, func(ctx convey.C) {
  358. err := d.DeleteRealnameInfo(c, mid)
  359. ctx.Convey("Error should be nil", func(ctx convey.C) {
  360. ctx.So(err, convey.ShouldBeNil)
  361. })
  362. })
  363. }
  364. func TestDaoSetRealnameCaptureCode(t *testing.T) {
  365. var (
  366. c = context.Background()
  367. mid = int64(19476037)
  368. code = int(0)
  369. )
  370. convey.Convey("SetRealnameCaptureCode", t, func(ctx convey.C) {
  371. err := d.SetRealnameCaptureCode(c, mid, code)
  372. ctx.Convey("Error should be nil", func(ctx convey.C) {
  373. ctx.So(err, convey.ShouldBeNil)
  374. })
  375. })
  376. }
  377. func TestDaoDeleteRealnameCaptureCode(t *testing.T) {
  378. var (
  379. c = context.Background()
  380. mid = int64(19476037)
  381. )
  382. convey.Convey("DeleteRealnameCaptureCode", t, func(ctx convey.C) {
  383. err := d.DeleteRealnameCaptureCode(c, mid)
  384. ctx.Convey("Error should be nil", func(ctx convey.C) {
  385. ctx.So(err, convey.ShouldBeNil)
  386. })
  387. })
  388. }
  389. func TestDaoSetRealnameCaptureErrTimes(t *testing.T) {
  390. var (
  391. c = context.Background()
  392. mid = int64(19476037)
  393. times = int(0)
  394. )
  395. convey.Convey("SetRealnameCaptureErrTimes", t, func(ctx convey.C) {
  396. err := d.SetRealnameCaptureErrTimes(c, mid, times)
  397. ctx.Convey("Error should be nil", func(ctx convey.C) {
  398. ctx.So(err, convey.ShouldBeNil)
  399. })
  400. })
  401. }
  402. func TestDaoRealnameCaptureErrTimesCache(t *testing.T) {
  403. var (
  404. c = context.Background()
  405. mid = int64(19476037)
  406. )
  407. convey.Convey("RealnameCaptureErrTimesCache", t, func(ctx convey.C) {
  408. times, err := d.RealnameCaptureErrTimesCache(c, mid)
  409. ctx.Convey("Error should be nil", func(ctx convey.C) {
  410. ctx.So(err, convey.ShouldBeNil)
  411. })
  412. ctx.Convey("times should not be nil", func(ctx convey.C) {
  413. ctx.So(times, convey.ShouldNotBeNil)
  414. })
  415. })
  416. }
  417. func TestDaoIncreaseRealnameCaptureErrTimes(t *testing.T) {
  418. var (
  419. c = context.Background()
  420. mid = int64(19476037)
  421. )
  422. convey.Convey("IncreaseRealnameCaptureErrTimes", t, func(ctx convey.C) {
  423. err := d.IncreaseRealnameCaptureErrTimes(c, mid)
  424. ctx.Convey("Error should be nil", func(ctx convey.C) {
  425. ctx.So(err, convey.ShouldBeNil)
  426. })
  427. })
  428. }
  429. func TestDaoDeleteRealnameCaptureErrTimes(t *testing.T) {
  430. var (
  431. c = context.Background()
  432. mid = int64(19476037)
  433. )
  434. convey.Convey("DeleteRealnameCaptureErrTimes", t, func(ctx convey.C) {
  435. err := d.DeleteRealnameCaptureErrTimes(c, mid)
  436. ctx.Convey("Error should be nil", func(ctx convey.C) {
  437. ctx.So(err, convey.ShouldBeNil)
  438. })
  439. })
  440. }