mc_test.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/account/model"
  6. mc "go-common/library/cache/memcache"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaokeyInfo(t *testing.T) {
  10. var (
  11. mid = int64(2205)
  12. )
  13. convey.Convey("Generate info-key", t, func(ctx convey.C) {
  14. p1 := keyInfo(mid)
  15. ctx.Convey("Then info-key should contains info prefix.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldContainSubstring, _prefixInfo)
  17. })
  18. })
  19. }
  20. func TestDaokeyCard(t *testing.T) {
  21. var (
  22. mid = int64(2205)
  23. )
  24. convey.Convey("Generate card-info-key", t, func(ctx convey.C) {
  25. p1 := keyCard(mid)
  26. ctx.Convey("Then card-info-key should contains card prefix.", func(ctx convey.C) {
  27. ctx.So(p1, convey.ShouldContainSubstring, _prefixCard)
  28. })
  29. })
  30. }
  31. func TestDaokeyVip(t *testing.T) {
  32. var (
  33. mid = int64(2205)
  34. )
  35. convey.Convey("Generate vip-info-key", t, func(ctx convey.C) {
  36. p1 := keyVip(mid)
  37. ctx.Convey("Then vip-info-key should contains vip prefix.", func(ctx convey.C) {
  38. ctx.So(p1, convey.ShouldContainSubstring, _prefixVip)
  39. })
  40. })
  41. }
  42. func TestDaokeyProfile(t *testing.T) {
  43. var (
  44. mid = int64(2205)
  45. )
  46. convey.Convey("Generate profile-key", t, func(ctx convey.C) {
  47. p1 := keyProfile(mid)
  48. ctx.Convey("Then profile-key should contains profile prefix.", func(ctx convey.C) {
  49. ctx.So(p1, convey.ShouldContainSubstring, _prefixProfile)
  50. })
  51. })
  52. }
  53. func TestDaoCacheInfo(t *testing.T) {
  54. var (
  55. c = context.TODO()
  56. mid = int64(2205)
  57. )
  58. convey.Convey("Get member base-info from cache", t, func(ctx convey.C) {
  59. _, err := d.CacheInfo(c, mid)
  60. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. }
  65. func TestDaoAddCacheInfo(t *testing.T) {
  66. var (
  67. c = context.TODO()
  68. mid = int64(2205)
  69. v = &model.Info{
  70. Mid: 2205,
  71. Name: "Haha",
  72. Sex: "男",
  73. Face: "http://i1.hdslb.com/bfs/face/4b12a3e65d344e31a11e6425767863019738c7bc.jpg",
  74. Sign: "来电只是",
  75. Rank: 500,
  76. }
  77. )
  78. convey.Convey("Add member base-info to cache", t, func(ctx convey.C) {
  79. err := d.AddCacheInfo(c, mid, v)
  80. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  81. ctx.So(err, convey.ShouldBeNil)
  82. })
  83. })
  84. }
  85. func TestDaoCacheInfos(t *testing.T) {
  86. var (
  87. c = context.TODO()
  88. mids = []int64{2205, 2805}
  89. )
  90. convey.Convey("Batch get members' base-info", t, func(ctx convey.C) {
  91. res, err := d.CacheInfos(c, mids)
  92. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. ctx.So(res, convey.ShouldNotBeNil)
  95. })
  96. })
  97. }
  98. func TestDaoAddCacheInfos(t *testing.T) {
  99. var (
  100. c = context.TODO()
  101. im = map[int64]*model.Info{
  102. 2205: {
  103. Mid: 2205,
  104. Name: "板桥真菜",
  105. Sex: "2",
  106. Face: "/bfs/face/e93098c3aa8c18b24001740e707ebe2df180f5f7.jpg",
  107. Sign: "没有",
  108. Rank: 10000,
  109. },
  110. 3305: {
  111. Mid: 3305,
  112. Name: "FGNB",
  113. Sex: "1",
  114. Face: "/bfs/face/e93098c3aa8c18b24001740e707ebe2df180f5f7.jpg",
  115. Sign: "啦啦",
  116. Rank: 5000,
  117. },
  118. }
  119. )
  120. convey.Convey("Batch set members' base-info to cache", t, func(ctx convey.C) {
  121. err := d.AddCacheInfos(c, im)
  122. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  123. ctx.So(err, convey.ShouldBeNil)
  124. })
  125. })
  126. }
  127. func TestDaoCacheCard(t *testing.T) {
  128. var (
  129. c = context.TODO()
  130. mid = int64(2805)
  131. )
  132. convey.Convey("Get card-info from cache", t, func(ctx convey.C) {
  133. _, err := d.CacheCard(c, mid)
  134. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. })
  137. })
  138. }
  139. func TestDaoAddCacheCard(t *testing.T) {
  140. var (
  141. c = context.TODO()
  142. mid = int64(2805)
  143. v = &model.Card{
  144. Mid: 10920044,
  145. Name: "冠冠爱看书",
  146. Sex: "男",
  147. Face: "http://i1.hdslb.com/bfs/face/4b12a3e65d344e31a11e6425767863019738c7bc.jpg",
  148. Sign: "来点字",
  149. Rank: 10000,
  150. Level: 5, //等级
  151. Silence: 0,
  152. Vip: model.VipInfo{
  153. Type: 2,
  154. Status: 1,
  155. DueDate: 162930240,
  156. },
  157. Pendant: model.PendantInfo{
  158. Pid: 159,
  159. Name: "2018拜年祭",
  160. Image: "http://i2.hdslb.com/bfs/face/aace621fa64a698f2ca94d13645a26e9a7a99ed2.png",
  161. Expire: 1566367231,
  162. },
  163. Nameplate: model.NameplateInfo{
  164. Nid: 7,
  165. Name: "见习搬运工",
  166. Image: "http://i1.hdslb.com/bfs/face/8478fb7c54026cd47f09daa493a1b1683113a90d.png",
  167. ImageSmall: "http://i0.hdslb.com/bfs/face/50eef47c3a30a75659d3cc298cfb09031d1a2ce5.png",
  168. Level: "普通勋章",
  169. Condition: "转载视频",
  170. },
  171. }
  172. )
  173. convey.Convey("Add card-info to cache", t, func(ctx convey.C) {
  174. err := d.AddCacheCard(c, mid, v)
  175. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  176. ctx.So(err, convey.ShouldBeNil)
  177. })
  178. })
  179. }
  180. func TestDaoCacheCards(t *testing.T) {
  181. var (
  182. c = context.TODO()
  183. mids = []int64{110017381, 110019061, 110020081}
  184. )
  185. convey.Convey("Batch get card-info from cache", t, func(ctx convey.C) {
  186. res, err := d.CacheCards(c, mids)
  187. ctx.Convey("Then err should be nil and res should not be nil.", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldBeNil)
  189. ctx.So(res, convey.ShouldNotBeNil)
  190. })
  191. })
  192. }
  193. func TestDaoAddCacheCards(t *testing.T) {
  194. var (
  195. c = context.TODO()
  196. card1 = &model.Card{
  197. Mid: 10920044,
  198. Name: "冠冠爱看书",
  199. Sex: "男",
  200. Face: "http://i1.hdslb.com/bfs/face/4b12a3e65d344e31a11e6425767863019738c7bc.jpg",
  201. Sign: "来点字",
  202. Rank: 10000,
  203. Level: 5, //等级
  204. Silence: 0,
  205. Vip: model.VipInfo{
  206. Type: 2,
  207. Status: 1,
  208. DueDate: 162930240,
  209. },
  210. Pendant: model.PendantInfo{
  211. Pid: 159,
  212. Name: "2018拜年祭",
  213. Image: "http://i2.hdslb.com/bfs/face/aace621fa64a698f2ca94d13645a26e9a7a99ed2.png",
  214. Expire: 1566367231,
  215. },
  216. Nameplate: model.NameplateInfo{
  217. Nid: 7,
  218. Name: "见习搬运工",
  219. Image: "http://i1.hdslb.com/bfs/face/8478fb7c54026cd47f09daa493a1b1683113a90d.png",
  220. ImageSmall: "http://i0.hdslb.com/bfs/face/50eef47c3a30a75659d3cc298cfb09031d1a2ce5.png",
  221. Level: "普通勋章",
  222. Condition: "转载视频",
  223. },
  224. }
  225. cm = map[int64]*model.Card{
  226. card1.Mid: card1,
  227. }
  228. )
  229. convey.Convey("Batch set card-info to cache", t, func(ctx convey.C) {
  230. err := d.AddCacheCards(c, cm)
  231. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  232. ctx.So(err, convey.ShouldBeNil)
  233. })
  234. })
  235. }
  236. func TestDaoCacheVip(t *testing.T) {
  237. var (
  238. c = context.TODO()
  239. mid = int64(110003731)
  240. )
  241. convey.Convey("Get vip-info from cache", t, func(ctx convey.C) {
  242. _, err := d.CacheVip(c, mid)
  243. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  244. ctx.So(err, convey.ShouldBeNil)
  245. })
  246. })
  247. }
  248. func TestDaoAddCacheVip(t *testing.T) {
  249. var (
  250. c = context.TODO()
  251. mid = int64(110003731)
  252. v = &model.VipInfo{
  253. Type: 2,
  254. Status: 1,
  255. DueDate: 162930240,
  256. }
  257. )
  258. convey.Convey("Set vip-cache to cache", t, func(ctx convey.C) {
  259. err := d.AddCacheVip(c, mid, v)
  260. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  261. ctx.So(err, convey.ShouldBeNil)
  262. })
  263. })
  264. }
  265. func TestDaoCacheVips(t *testing.T) {
  266. var (
  267. c = context.TODO()
  268. mids = []int64{110002741, 110004601, 110006251}
  269. )
  270. convey.Convey("Batch get vip-infos from cache", t, func(ctx convey.C) {
  271. res, err := d.CacheVips(c, mids)
  272. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  273. ctx.So(err, convey.ShouldBeNil)
  274. ctx.So(res, convey.ShouldNotBeNil)
  275. })
  276. })
  277. }
  278. func TestDaoAddCacheVips(t *testing.T) {
  279. var (
  280. c = context.TODO()
  281. vm = map[int64]*model.VipInfo{
  282. 110007391: {
  283. Type: 2,
  284. Status: 1,
  285. DueDate: 162930240,
  286. },
  287. 110010271: {
  288. Type: 2,
  289. Status: 1,
  290. DueDate: 162930240,
  291. },
  292. }
  293. )
  294. convey.Convey("Batch set vip-infos to cache", t, func(ctx convey.C) {
  295. err := d.AddCacheVips(c, vm)
  296. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  297. ctx.So(err, convey.ShouldBeNil)
  298. })
  299. })
  300. }
  301. func TestDaoCacheProfile(t *testing.T) {
  302. var (
  303. c = context.TODO()
  304. mid = int64(110011831)
  305. )
  306. convey.Convey("Get profile-info from cache", t, func(ctx convey.C) {
  307. _, err := d.CacheProfile(c, mid)
  308. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  309. ctx.So(err, convey.ShouldBeNil)
  310. })
  311. })
  312. }
  313. func TestDaoAddCacheProfile(t *testing.T) {
  314. var (
  315. c = context.TODO()
  316. mid = int64(110011951)
  317. v = &model.Profile{
  318. Mid: 10920044,
  319. Name: "冠冠爱看书",
  320. Sex: "男",
  321. Face: "http://i1.hdslb.com/bfs/face/4b12a3e65d344e31a11e6425767863019738c7bc.jpg",
  322. Sign: "来点字",
  323. Rank: 10000,
  324. Level: 5,
  325. JoinTime: 1503296503,
  326. Moral: 71,
  327. Silence: 0,
  328. EmailStatus: 1,
  329. TelStatus: 1,
  330. Identification: 0,
  331. Vip: model.VipInfo{
  332. Type: 2,
  333. Status: 1,
  334. DueDate: 1629302400000,
  335. },
  336. Pendant: model.PendantInfo{
  337. Pid: 159,
  338. Name: "2018拜年祭",
  339. Image: "http://i2.hdslb.com/bfs/face/aace621fa64a698f2ca94d13645a26e9a7a99ed2.png",
  340. Expire: 1551413548,
  341. },
  342. Nameplate: model.NameplateInfo{
  343. Nid: 7,
  344. Name: "见习搬运工",
  345. Image: "http://i1.hdslb.com/bfs/face/8478fb7c54026cd47f09daa493a1b1683113a90d.png",
  346. ImageSmall: "http://i0.hdslb.com/bfs/face/50eef47c3a30a75659d3cc298cfb09031d1a2ce5.png",
  347. Level: "普通勋章",
  348. Condition: "转载视频投稿通过总数>=10",
  349. },
  350. }
  351. )
  352. convey.Convey("Set profile-info to cache", t, func(ctx convey.C) {
  353. err := d.AddCacheProfile(c, mid, v)
  354. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  355. ctx.So(err, convey.ShouldBeNil)
  356. })
  357. })
  358. }
  359. func TestDaoDelCache(t *testing.T) {
  360. var (
  361. c = context.TODO()
  362. mid = int64(110014081)
  363. )
  364. convey.Convey("Delete member's cache", t, func(ctx convey.C) {
  365. errs := d.DelCache(c, mid)
  366. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  367. for _, e := range errs {
  368. if e != mc.ErrNotFound {
  369. ctx.So(e, convey.ShouldBeNil)
  370. }
  371. }
  372. })
  373. })
  374. }