mysql_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/favorite/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestFavfolderHit(t *testing.T) {
  9. var (
  10. mid = int64(0)
  11. )
  12. convey.Convey("folderHit", t, func(ctx convey.C) {
  13. p1 := folderHit(mid)
  14. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestFavrelationHit(t *testing.T) {
  20. var (
  21. mid = int64(0)
  22. )
  23. convey.Convey("relationHit", t, func(ctx convey.C) {
  24. p1 := relationHit(mid)
  25. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  26. ctx.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestFavusersHit(t *testing.T) {
  31. var (
  32. oid = int64(0)
  33. )
  34. convey.Convey("usersHit", t, func(ctx convey.C) {
  35. p1 := usersHit(oid)
  36. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  37. ctx.So(p1, convey.ShouldNotBeNil)
  38. })
  39. })
  40. }
  41. func TestFavcountHit(t *testing.T) {
  42. var (
  43. oid = int64(0)
  44. )
  45. convey.Convey("countHit", t, func(ctx convey.C) {
  46. p1 := countHit(oid)
  47. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  48. ctx.So(p1, convey.ShouldNotBeNil)
  49. })
  50. })
  51. }
  52. func TestFavpingMySQL(t *testing.T) {
  53. var (
  54. c = context.TODO()
  55. )
  56. convey.Convey("pingMySQL", t, func(ctx convey.C) {
  57. err := d.pingMySQL(c)
  58. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. })
  61. })
  62. }
  63. func TestFavFolder(t *testing.T) {
  64. var (
  65. c = context.TODO()
  66. tp = int8(1)
  67. mid = int64(88888894)
  68. fid = int64(1)
  69. )
  70. convey.Convey("Folder", t, func(ctx convey.C) {
  71. f, err := d.Folder(c, tp, mid, fid)
  72. ctx.Convey("Then err should be nil.f should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(f, convey.ShouldNotBeNil)
  75. })
  76. })
  77. }
  78. func TestFavFolderByName(t *testing.T) {
  79. var (
  80. c = context.TODO()
  81. tp = int8(0)
  82. mid = int64(0)
  83. name = ""
  84. )
  85. convey.Convey("FolderByName", t, func(ctx convey.C) {
  86. f, err := d.FolderByName(c, tp, mid, name)
  87. ctx.Convey("Then err should be nil.f should not be nil.", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. ctx.So(f, convey.ShouldNotBeNil)
  90. })
  91. })
  92. }
  93. func TestFavDefaultFolder(t *testing.T) {
  94. var (
  95. c = context.TODO()
  96. tp = int8(0)
  97. mid = int64(0)
  98. )
  99. convey.Convey("DefaultFolder", t, func(ctx convey.C) {
  100. f, err := d.DefaultFolder(c, tp, mid)
  101. ctx.Convey("Then err should be nil.f should not be nil.", func(ctx convey.C) {
  102. ctx.So(err, convey.ShouldBeNil)
  103. ctx.So(f, convey.ShouldNotBeNil)
  104. })
  105. })
  106. }
  107. func TestFavAddFolder(t *testing.T) {
  108. var (
  109. c = context.TODO()
  110. f = &model.Folder{}
  111. )
  112. convey.Convey("AddFolder", t, func(ctx convey.C) {
  113. fid, err := d.AddFolder(c, f)
  114. ctx.Convey("Then err should be nil.fid should not be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(fid, convey.ShouldNotBeNil)
  117. })
  118. })
  119. }
  120. func TestFavUpdateFolder(t *testing.T) {
  121. var (
  122. c = context.TODO()
  123. f = &model.Folder{}
  124. )
  125. convey.Convey("UpdateFolder", t, func(ctx convey.C) {
  126. fid, err := d.UpdateFolder(c, f)
  127. ctx.Convey("Then err should be nil.fid should not be nil.", func(ctx convey.C) {
  128. ctx.So(err, convey.ShouldBeNil)
  129. ctx.So(fid, convey.ShouldNotBeNil)
  130. })
  131. })
  132. }
  133. func TestFavUpFolderName(t *testing.T) {
  134. var (
  135. c = context.TODO()
  136. typ = int8(0)
  137. mid = int64(0)
  138. fid = int64(0)
  139. name = ""
  140. )
  141. convey.Convey("UpFolderName", t, func(ctx convey.C) {
  142. rows, err := d.UpFolderName(c, typ, mid, fid, name)
  143. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  144. ctx.So(err, convey.ShouldBeNil)
  145. ctx.So(rows, convey.ShouldNotBeNil)
  146. })
  147. })
  148. }
  149. func TestFavUpFolderAttr(t *testing.T) {
  150. var (
  151. c = context.TODO()
  152. typ = int8(0)
  153. mid = int64(0)
  154. fid = int64(0)
  155. attr = int32(0)
  156. )
  157. convey.Convey("UpFolderAttr", t, func(ctx convey.C) {
  158. rows, err := d.UpFolderAttr(c, typ, mid, fid, attr)
  159. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  160. ctx.So(err, convey.ShouldBeNil)
  161. ctx.So(rows, convey.ShouldNotBeNil)
  162. })
  163. })
  164. }
  165. func TestFavFolderRelations(t *testing.T) {
  166. var (
  167. c = context.TODO()
  168. typ = int8(0)
  169. mid = int64(0)
  170. fid = int64(0)
  171. start = int(0)
  172. end = int(0)
  173. )
  174. convey.Convey("FolderRelations", t, func(ctx convey.C) {
  175. fr, err := d.FolderRelations(c, typ, mid, fid, start, end)
  176. ctx.Convey("Then err should be nil.fr should not be nil.", func(ctx convey.C) {
  177. ctx.So(err, convey.ShouldBeNil)
  178. ctx.So(fr, convey.ShouldNotBeNil)
  179. })
  180. })
  181. }
  182. func TestFavFolders(t *testing.T) {
  183. var (
  184. c = context.TODO()
  185. fvmids = []*model.ArgFVmid{}
  186. )
  187. convey.Convey("Folders", t, func(ctx convey.C) {
  188. fs, err := d.Folders(c, fvmids)
  189. ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
  190. ctx.So(err, convey.ShouldBeNil)
  191. ctx.So(fs, convey.ShouldNotBeNil)
  192. })
  193. })
  194. }
  195. func TestFavRelationFidsByOid(t *testing.T) {
  196. var (
  197. c = context.TODO()
  198. tp = int8(1)
  199. mid = int64(88888894)
  200. oid = int64(1)
  201. )
  202. convey.Convey("RelationFidsByOid", t, func(ctx convey.C) {
  203. _, err := d.RelationFidsByOid(c, tp, mid, oid)
  204. ctx.Convey("Then err should be nil.fids should not be nil.", func(ctx convey.C) {
  205. ctx.So(err, convey.ShouldBeNil)
  206. })
  207. })
  208. }
  209. func TestFavRelationFidsByOids(t *testing.T) {
  210. var (
  211. c = context.TODO()
  212. tp = int8(1)
  213. mid = int64(8888894)
  214. oids = []int64{1, 2, 3}
  215. )
  216. convey.Convey("RelationFidsByOids", t, func(ctx convey.C) {
  217. fidsMap, err := d.RelationFidsByOids(c, tp, mid, oids)
  218. ctx.Convey("Then err should be nil.fidsMap should not be nil.", func(ctx convey.C) {
  219. ctx.So(err, convey.ShouldBeNil)
  220. ctx.So(fidsMap, convey.ShouldNotBeNil)
  221. })
  222. })
  223. }
  224. func TestFavCntRelations(t *testing.T) {
  225. var (
  226. c = context.TODO()
  227. mid = int64(0)
  228. fid = int64(0)
  229. )
  230. convey.Convey("CntRelations", t, func(ctx convey.C) {
  231. count, err := d.CntRelations(c, mid, fid, 2)
  232. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  233. ctx.So(err, convey.ShouldBeNil)
  234. ctx.So(count, convey.ShouldNotBeNil)
  235. })
  236. })
  237. }
  238. func TestFavFolderCnt(t *testing.T) {
  239. var (
  240. c = context.TODO()
  241. tp = int8(0)
  242. mid = int64(0)
  243. )
  244. convey.Convey("FolderCnt", t, func(ctx convey.C) {
  245. count, err := d.FolderCnt(c, tp, mid)
  246. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  247. ctx.So(err, convey.ShouldBeNil)
  248. ctx.So(count, convey.ShouldNotBeNil)
  249. })
  250. })
  251. }
  252. func TestFavAddFav(t *testing.T) {
  253. var (
  254. c = context.TODO()
  255. fr = &model.Favorite{}
  256. )
  257. convey.Convey("AddFav", t, func(ctx convey.C) {
  258. rows, err := d.AddFav(c, fr)
  259. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  260. ctx.So(err, convey.ShouldBeNil)
  261. ctx.So(rows, convey.ShouldNotBeNil)
  262. })
  263. })
  264. }
  265. func TestFavDelFav(t *testing.T) {
  266. var (
  267. c = context.TODO()
  268. tp = int8(0)
  269. mid = int64(0)
  270. fid = int64(0)
  271. oid = int64(0)
  272. )
  273. convey.Convey("DelFav", t, func(ctx convey.C) {
  274. rows, err := d.DelFav(c, tp, mid, fid, oid)
  275. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  276. ctx.So(err, convey.ShouldBeNil)
  277. ctx.So(rows, convey.ShouldNotBeNil)
  278. })
  279. })
  280. }
  281. func TestFavAddRelation(t *testing.T) {
  282. var (
  283. c = context.TODO()
  284. fr = &model.Favorite{}
  285. )
  286. convey.Convey("AddRelation", t, func(ctx convey.C) {
  287. rows, err := d.AddRelation(c, fr)
  288. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  289. ctx.So(err, convey.ShouldBeNil)
  290. ctx.So(rows, convey.ShouldNotBeNil)
  291. })
  292. })
  293. }
  294. func TestFavRelation(t *testing.T) {
  295. var (
  296. c = context.TODO()
  297. tp = int8(0)
  298. mid = int64(0)
  299. fid = int64(0)
  300. oid = int64(0)
  301. )
  302. convey.Convey("Relation", t, func(ctx convey.C) {
  303. _, err := d.Relation(c, tp, mid, fid, oid)
  304. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  305. ctx.So(err, convey.ShouldBeNil)
  306. })
  307. })
  308. }
  309. func TestFavDelRelation(t *testing.T) {
  310. var (
  311. c = context.TODO()
  312. tp = int8(0)
  313. mid = int64(0)
  314. fid = int64(0)
  315. oid = int64(0)
  316. )
  317. convey.Convey("DelRelation", t, func(ctx convey.C) {
  318. rows, err := d.DelRelation(c, tp, mid, fid, oid)
  319. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  320. ctx.So(err, convey.ShouldBeNil)
  321. ctx.So(rows, convey.ShouldNotBeNil)
  322. })
  323. })
  324. }
  325. func TestFavMultiDelRelations(t *testing.T) {
  326. var (
  327. c = context.TODO()
  328. tp = int8(1)
  329. mid = int64(88888894)
  330. fid = int64(0)
  331. oids = []int64{1, 2, 3}
  332. )
  333. convey.Convey("MultiDelRelations", t, func(ctx convey.C) {
  334. rows, err := d.MultiDelRelations(c, tp, mid, fid, oids)
  335. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  336. ctx.So(err, convey.ShouldBeNil)
  337. ctx.So(rows, convey.ShouldNotBeNil)
  338. })
  339. })
  340. }
  341. func TestFavTxMultiDelRelations(t *testing.T) {
  342. var (
  343. tx, _ = d.BeginTran(context.TODO())
  344. tp = int8(1)
  345. mid = int64(88888894)
  346. fid = int64(0)
  347. oids = []int64{1, 2, 3}
  348. )
  349. convey.Convey("TxMultiDelRelations", t, func(ctx convey.C) {
  350. rows, err := d.TxMultiDelRelations(tx, tp, mid, fid, oids)
  351. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  352. ctx.So(err, convey.ShouldBeNil)
  353. ctx.So(rows, convey.ShouldNotBeNil)
  354. })
  355. })
  356. }
  357. func TestFavMultiAddRelations(t *testing.T) {
  358. var (
  359. c = context.TODO()
  360. tp = int8(1)
  361. mid = int64(88888894)
  362. fid = int64(0)
  363. oids = []int64{1}
  364. )
  365. convey.Convey("MultiAddRelations", t, func(ctx convey.C) {
  366. rows, err := d.MultiAddRelations(c, tp, mid, fid, oids)
  367. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  368. ctx.So(err, convey.ShouldBeNil)
  369. ctx.So(rows, convey.ShouldNotBeNil)
  370. })
  371. })
  372. }
  373. func TestFavDelFolder(t *testing.T) {
  374. var (
  375. c = context.TODO()
  376. tp = int8(0)
  377. mid = int64(0)
  378. fid = int64(0)
  379. )
  380. convey.Convey("DelFolder", t, func(ctx convey.C) {
  381. rows, err := d.DelFolder(c, tp, mid, fid)
  382. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  383. ctx.So(err, convey.ShouldBeNil)
  384. ctx.So(rows, convey.ShouldNotBeNil)
  385. })
  386. })
  387. }
  388. func TestFavUserFolders(t *testing.T) {
  389. var (
  390. c = context.TODO()
  391. typ = int8(0)
  392. mid = int64(0)
  393. )
  394. convey.Convey("UserFolders", t, func(ctx convey.C) {
  395. fs, err := d.UserFolders(c, typ, mid)
  396. ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
  397. ctx.So(err, convey.ShouldBeNil)
  398. ctx.So(fs, convey.ShouldNotBeNil)
  399. })
  400. })
  401. }
  402. func TestFavFolderSort(t *testing.T) {
  403. var (
  404. c = context.TODO()
  405. typ = int8(0)
  406. mid = int64(0)
  407. )
  408. convey.Convey("FolderSort", t, func(ctx convey.C) {
  409. fst, err := d.FolderSort(c, typ, mid)
  410. ctx.Convey("Then err should be nil.fst should not be nil.", func(ctx convey.C) {
  411. ctx.So(err, convey.ShouldBeNil)
  412. ctx.So(fst, convey.ShouldNotBeNil)
  413. })
  414. })
  415. }
  416. func TestFavUpFolderSort(t *testing.T) {
  417. var (
  418. c = context.TODO()
  419. fst = &model.FolderSort{}
  420. )
  421. convey.Convey("UpFolderSort", t, func(ctx convey.C) {
  422. rows, err := d.UpFolderSort(c, fst)
  423. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  424. ctx.So(err, convey.ShouldBeNil)
  425. ctx.So(rows, convey.ShouldNotBeNil)
  426. })
  427. })
  428. }
  429. func TestFavRecentOids(t *testing.T) {
  430. var (
  431. c = context.TODO()
  432. mid = int64(88888894)
  433. fid = int64(1)
  434. )
  435. convey.Convey("RecentOids", t, func(ctx convey.C) {
  436. oids, err := d.RecentOids(c, mid, fid, 1)
  437. ctx.Convey("Then err should be nil.oids should not be nil.", func(ctx convey.C) {
  438. ctx.So(err, convey.ShouldBeNil)
  439. ctx.So(oids, convey.ShouldNotBeNil)
  440. })
  441. })
  442. }
  443. func TestFavTxCopyRelations(t *testing.T) {
  444. var (
  445. tx, _ = d.BeginTran(context.TODO())
  446. typ = int8(1)
  447. oldmid = int64(88888894)
  448. mid = int64(88888894)
  449. oldfid = int64(0)
  450. newfid = int64(0)
  451. oids = []int64{1}
  452. )
  453. convey.Convey("TxCopyRelations", t, func(ctx convey.C) {
  454. rows, err := d.TxCopyRelations(tx, typ, oldmid, mid, oldfid, newfid, oids)
  455. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  456. ctx.So(err, convey.ShouldBeNil)
  457. ctx.So(rows, convey.ShouldNotBeNil)
  458. })
  459. })
  460. }
  461. func TestFavCopyRelations(t *testing.T) {
  462. var (
  463. c = context.TODO()
  464. typ = int8(1)
  465. oldmid = int64(88888894)
  466. mid = int64(88888894)
  467. oldfid = int64(0)
  468. newfid = int64(0)
  469. oids = []int64{1}
  470. )
  471. convey.Convey("CopyRelations", t, func(ctx convey.C) {
  472. rows, err := d.CopyRelations(c, typ, oldmid, mid, oldfid, newfid, oids)
  473. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  474. ctx.So(err, convey.ShouldBeNil)
  475. ctx.So(rows, convey.ShouldNotBeNil)
  476. })
  477. })
  478. }
  479. func TestFavCntUsers(t *testing.T) {
  480. var (
  481. c = context.TODO()
  482. typ = int8(0)
  483. oid = int64(0)
  484. )
  485. convey.Convey("CntUsers", t, func(ctx convey.C) {
  486. count, err := d.CntUsers(c, typ, oid)
  487. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  488. ctx.So(err, convey.ShouldBeNil)
  489. ctx.So(count, convey.ShouldNotBeNil)
  490. })
  491. })
  492. }
  493. func TestFavUsers(t *testing.T) {
  494. var (
  495. c = context.TODO()
  496. typ = int8(0)
  497. oid = int64(0)
  498. start = int(0)
  499. end = int(0)
  500. )
  501. convey.Convey("Users", t, func(ctx convey.C) {
  502. us, err := d.Users(c, typ, oid, start, end)
  503. ctx.Convey("Then err should be nil.us should not be nil.", func(ctx convey.C) {
  504. ctx.So(err, convey.ShouldBeNil)
  505. ctx.So(us, convey.ShouldNotBeNil)
  506. })
  507. })
  508. }
  509. func TestFavOidCount(t *testing.T) {
  510. var (
  511. c = context.TODO()
  512. typ = int8(0)
  513. oid = int64(0)
  514. )
  515. convey.Convey("OidCount", t, func(ctx convey.C) {
  516. count, err := d.OidCount(c, typ, oid)
  517. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  518. ctx.So(err, convey.ShouldBeNil)
  519. ctx.So(count, convey.ShouldNotBeNil)
  520. })
  521. })
  522. }
  523. func TestFavOidsCount(t *testing.T) {
  524. var (
  525. c = context.TODO()
  526. typ = int8(1)
  527. oids = []int64{1, 2, 3}
  528. )
  529. convey.Convey("OidsCount", t, func(ctx convey.C) {
  530. counts, err := d.OidsCount(c, typ, oids)
  531. ctx.Convey("Then err should be nil.counts should not be nil.", func(ctx convey.C) {
  532. ctx.So(err, convey.ShouldBeNil)
  533. ctx.So(counts, convey.ShouldNotBeNil)
  534. })
  535. })
  536. }
  537. func TestFavBatchOids(t *testing.T) {
  538. var (
  539. c = context.TODO()
  540. typ = int8(1)
  541. mid = int64(88888894)
  542. limit = int(10)
  543. )
  544. convey.Convey("BatchOids", t, func(ctx convey.C) {
  545. oids, err := d.BatchOids(c, typ, mid, limit)
  546. ctx.Convey("Then err should be nil.oids should not be nil.", func(ctx convey.C) {
  547. ctx.So(err, convey.ShouldBeNil)
  548. ctx.So(oids, convey.ShouldNotBeNil)
  549. })
  550. })
  551. }