mysql_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/dm2/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaohitSubject(t *testing.T) {
  9. convey.Convey("hitSubject", t, func(ctx convey.C) {
  10. var (
  11. oid = int64(0)
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1 := testDao.hitSubject(oid)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDaohitIndex(t *testing.T) {
  22. convey.Convey("hitIndex", t, func(ctx convey.C) {
  23. var (
  24. oid = int64(0)
  25. )
  26. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  27. p1 := testDao.hitIndex(oid)
  28. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaohitContent(t *testing.T) {
  35. convey.Convey("hitContent", t, func(ctx convey.C) {
  36. var (
  37. oid = int64(0)
  38. )
  39. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  40. p1 := testDao.hitContent(oid)
  41. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestDaohitSubtile(t *testing.T) {
  48. convey.Convey("hitSubtile", t, func(ctx convey.C) {
  49. var (
  50. oid = int64(0)
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. p1 := testDao.hitSubtile(oid)
  54. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  55. ctx.So(p1, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestDaoAddSubject(t *testing.T) {
  61. convey.Convey("AddSubject", t, func(ctx convey.C) {
  62. var (
  63. c = context.Background()
  64. tp = int32(0)
  65. oid = int64(0)
  66. pid = int64(0)
  67. mid = int64(0)
  68. maxlimit = int64(0)
  69. attr = int32(0)
  70. )
  71. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  72. testDao.AddSubject(c, tp, oid, pid, mid, maxlimit, attr)
  73. })
  74. })
  75. }
  76. func TestDaoUpdateSubAttr(t *testing.T) {
  77. convey.Convey("UpdateSubAttr", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. tp = int32(0)
  81. oid = int64(0)
  82. attr = int32(0)
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  85. affect, err := testDao.UpdateSubAttr(c, tp, oid, attr)
  86. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. ctx.So(affect, convey.ShouldNotBeNil)
  89. })
  90. })
  91. })
  92. }
  93. func TestDaoUpdateSubMid(t *testing.T) {
  94. convey.Convey("UpdateSubMid", t, func(ctx convey.C) {
  95. var (
  96. c = context.Background()
  97. tp = int32(0)
  98. oid = int64(0)
  99. mid = int64(0)
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. affect, err := testDao.UpdateSubMid(c, tp, oid, mid)
  103. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  104. ctx.So(err, convey.ShouldBeNil)
  105. ctx.So(affect, convey.ShouldNotBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestDaoSubject(t *testing.T) {
  111. convey.Convey("Subject", t, func(ctx convey.C) {
  112. var (
  113. c = context.Background()
  114. tp = int32(0)
  115. oid = int64(0)
  116. )
  117. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  118. s, err := testDao.Subject(c, tp, oid)
  119. ctx.Convey("Then err should be nil.s should not be nil.", func(ctx convey.C) {
  120. ctx.So(err, convey.ShouldBeNil)
  121. ctx.So(s, convey.ShouldNotBeNil)
  122. })
  123. })
  124. })
  125. }
  126. func TestDaoUpdateChildpool(t *testing.T) {
  127. convey.Convey("UpdateChildpool", t, func(ctx convey.C) {
  128. var (
  129. c = context.Background()
  130. tp = int32(0)
  131. oid = int64(0)
  132. childpool = int32(0)
  133. )
  134. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  135. affect, err := testDao.UpdateChildpool(c, tp, oid, childpool)
  136. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. ctx.So(affect, convey.ShouldNotBeNil)
  139. })
  140. })
  141. })
  142. }
  143. func TestDaoTxIncrSubjectCount(t *testing.T) {
  144. convey.Convey("TxIncrSubjectCount", t, func(ctx convey.C) {
  145. var (
  146. tx, _ = testDao.BeginTran(c)
  147. tp = int32(0)
  148. oid = int64(0)
  149. acount = int64(0)
  150. count = int64(0)
  151. childpool = int32(0)
  152. )
  153. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  154. affect, err := testDao.TxIncrSubjectCount(tx, tp, oid, acount, count, childpool)
  155. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  156. ctx.So(err, convey.ShouldBeNil)
  157. ctx.So(affect, convey.ShouldNotBeNil)
  158. })
  159. })
  160. ctx.Reset(func() {
  161. tx.Commit()
  162. })
  163. })
  164. }
  165. func TestDaoTxAddIndex(t *testing.T) {
  166. convey.Convey("TxAddIndex", t, func(ctx convey.C) {
  167. var (
  168. tx, _ = testDao.BeginTran(c)
  169. m = &model.DM{}
  170. )
  171. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  172. id, err := testDao.TxAddIndex(tx, m)
  173. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  174. ctx.So(err, convey.ShouldBeNil)
  175. ctx.So(id, convey.ShouldNotBeNil)
  176. })
  177. })
  178. ctx.Reset(func() {
  179. tx.Commit()
  180. })
  181. })
  182. }
  183. func TestDaoIndexs(t *testing.T) {
  184. convey.Convey("Indexs", t, func(ctx convey.C) {
  185. var (
  186. c = context.Background()
  187. tp = int32(0)
  188. oid = int64(0)
  189. )
  190. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  191. testDao.Indexs(c, tp, oid)
  192. })
  193. })
  194. }
  195. func TestDaoIndexsSeg(t *testing.T) {
  196. convey.Convey("IndexsSeg", t, func(ctx convey.C) {
  197. var (
  198. c = context.Background()
  199. tp = int32(0)
  200. oid = int64(0)
  201. ps = int64(0)
  202. pe = int64(0)
  203. limit = int64(0)
  204. pool = int32(0)
  205. )
  206. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  207. testDao.IndexsSeg(c, tp, oid, ps, pe, limit, pool)
  208. })
  209. })
  210. }
  211. func TestDaoIndexsSegID(t *testing.T) {
  212. convey.Convey("IndexsSegID", t, func(ctx convey.C) {
  213. var (
  214. c = context.Background()
  215. tp = int32(0)
  216. oid = int64(0)
  217. ps = int64(0)
  218. pe = int64(0)
  219. limit = int64(0)
  220. pool = int32(0)
  221. )
  222. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  223. testDao.IndexsSegID(c, tp, oid, ps, pe, limit, pool)
  224. })
  225. })
  226. }
  227. func TestDaoIndexsID(t *testing.T) {
  228. convey.Convey("IndexsID", t, func(ctx convey.C) {
  229. var (
  230. c = context.Background()
  231. tp = int32(0)
  232. oid = int64(0)
  233. pool = int32(0)
  234. )
  235. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  236. dmids, err := testDao.IndexsID(c, tp, oid, pool)
  237. ctx.Convey("Then err should be nil.dmids should not be nil.", func(ctx convey.C) {
  238. ctx.So(err, convey.ShouldBeNil)
  239. ctx.So(dmids, convey.ShouldNotBeNil)
  240. })
  241. })
  242. })
  243. }
  244. func TestDaoIndexsByid(t *testing.T) {
  245. convey.Convey("IndexsByid", t, func(ctx convey.C) {
  246. var (
  247. c = context.Background()
  248. tp = int32(0)
  249. oid = int64(0)
  250. dmids = []int64{}
  251. )
  252. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  253. testDao.IndexsByid(c, tp, oid, dmids)
  254. })
  255. })
  256. }
  257. func TestDaoIndexsByPool(t *testing.T) {
  258. convey.Convey("IndexsByPool", t, func(ctx convey.C) {
  259. var (
  260. c = context.Background()
  261. tp = int32(0)
  262. oid = int64(0)
  263. pool = int32(0)
  264. )
  265. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  266. dms, dmids, err := testDao.IndexsByPool(c, tp, oid, pool)
  267. ctx.Convey("Then err should be nil.dms,dmids should not be nil.", func(ctx convey.C) {
  268. ctx.So(err, convey.ShouldBeNil)
  269. ctx.So(dmids, convey.ShouldNotBeNil)
  270. ctx.So(dms, convey.ShouldNotBeNil)
  271. })
  272. })
  273. })
  274. }
  275. func TestDaoTxAddContent(t *testing.T) {
  276. convey.Convey("TxAddContent", t, func(ctx convey.C) {
  277. var (
  278. tx, _ = testDao.BeginTran(c)
  279. oid = int64(0)
  280. m = &model.Content{}
  281. )
  282. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  283. id, err := testDao.TxAddContent(tx, oid, m)
  284. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  285. ctx.So(err, convey.ShouldBeNil)
  286. ctx.So(id, convey.ShouldNotBeNil)
  287. })
  288. })
  289. ctx.Reset(func() {
  290. tx.Commit()
  291. })
  292. })
  293. }
  294. func TestDaoTxAddContentSpecial(t *testing.T) {
  295. convey.Convey("TxAddContentSpecial", t, func(ctx convey.C) {
  296. var (
  297. tx, _ = testDao.BeginTran(c)
  298. m = &model.ContentSpecial{}
  299. )
  300. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  301. id, err := testDao.TxAddContentSpecial(tx, m)
  302. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  303. ctx.So(err, convey.ShouldBeNil)
  304. ctx.So(id, convey.ShouldNotBeNil)
  305. })
  306. })
  307. ctx.Reset(func() {
  308. tx.Commit()
  309. })
  310. })
  311. }
  312. func TestDaoContent(t *testing.T) {
  313. convey.Convey("Content", t, func(ctx convey.C) {
  314. var (
  315. c = context.Background()
  316. oid = int64(0)
  317. dmid = int64(0)
  318. )
  319. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  320. ct, err := testDao.Content(c, oid, dmid)
  321. ctx.Convey("Then err should be nil.ct should not be nil.", func(ctx convey.C) {
  322. ctx.So(err, convey.ShouldBeNil)
  323. ctx.So(ct, convey.ShouldNotBeNil)
  324. })
  325. })
  326. })
  327. }
  328. func TestDaoContents(t *testing.T) {
  329. convey.Convey("Contents", t, func(ctx convey.C) {
  330. var (
  331. c = context.Background()
  332. oid = int64(0)
  333. dmids = []int64{}
  334. )
  335. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  336. ctsMap, err := testDao.Contents(c, oid, dmids)
  337. ctx.Convey("Then err should be nil.ctsMap should not be nil.", func(ctx convey.C) {
  338. ctx.So(err, convey.ShouldBeNil)
  339. ctx.So(ctsMap, convey.ShouldNotBeNil)
  340. })
  341. })
  342. })
  343. }
  344. func TestDaoContentsSpecial(t *testing.T) {
  345. convey.Convey("ContentsSpecial", t, func(ctx convey.C) {
  346. var (
  347. c = context.Background()
  348. dmids = []int64{123}
  349. )
  350. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  351. testDao.ContentsSpecial(c, dmids)
  352. })
  353. })
  354. }
  355. func TestDaoContentSpecial(t *testing.T) {
  356. convey.Convey("ContentSpecial", t, func(ctx convey.C) {
  357. var (
  358. c = context.Background()
  359. dmid = int64(0)
  360. )
  361. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  362. contentSpe, err := testDao.ContentSpecial(c, dmid)
  363. ctx.Convey("Then err should be nil.contentSpe should not be nil.", func(ctx convey.C) {
  364. ctx.So(err, convey.ShouldBeNil)
  365. ctx.So(contentSpe, convey.ShouldNotBeNil)
  366. })
  367. })
  368. })
  369. }
  370. func TestDaoDelDMHideState(t *testing.T) {
  371. convey.Convey("DelDMHideState", t, func(ctx convey.C) {
  372. var (
  373. c = context.Background()
  374. tp = int32(0)
  375. oid = int64(0)
  376. dmid = int64(0)
  377. )
  378. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  379. affect, err := testDao.DelDMHideState(c, tp, oid, dmid)
  380. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  381. ctx.So(err, convey.ShouldBeNil)
  382. ctx.So(affect, convey.ShouldNotBeNil)
  383. })
  384. })
  385. })
  386. }
  387. func TestDaoTxIncrSubMCount(t *testing.T) {
  388. convey.Convey("TxIncrSubMCount", t, func(ctx convey.C) {
  389. var (
  390. tx, _ = testDao.BeginTran(c)
  391. tp = int32(0)
  392. oid = int64(0)
  393. )
  394. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  395. affect, err := testDao.TxIncrSubMCount(tx, tp, oid)
  396. ctx.Convey("Then err should be nil.affect should not be nil.", func(ctx convey.C) {
  397. ctx.So(err, convey.ShouldBeNil)
  398. ctx.So(affect, convey.ShouldNotBeNil)
  399. })
  400. })
  401. ctx.Reset(func() {
  402. tx.Commit()
  403. })
  404. })
  405. }
  406. func TestDaoUpdateSubtitle(t *testing.T) {
  407. convey.Convey("UpdateSubtitle", t, func(ctx convey.C) {
  408. var (
  409. c = context.Background()
  410. subtitle = &model.Subtitle{}
  411. )
  412. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  413. err := testDao.UpdateSubtitle(c, subtitle)
  414. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  415. ctx.So(err, convey.ShouldBeNil)
  416. })
  417. })
  418. })
  419. }
  420. func TestDaoGetSubtitles(t *testing.T) {
  421. convey.Convey("GetSubtitles", t, func(ctx convey.C) {
  422. var (
  423. c = context.Background()
  424. tp = int32(0)
  425. oid = int64(0)
  426. )
  427. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  428. subtitles, err := testDao.GetSubtitles(c, tp, oid)
  429. ctx.Convey("Then err should be nil.subtitles should not be nil.", func(ctx convey.C) {
  430. ctx.So(err, convey.ShouldBeNil)
  431. ctx.So(subtitles, convey.ShouldNotBeNil)
  432. })
  433. })
  434. })
  435. }
  436. func TestDaoGetSubtitle(t *testing.T) {
  437. convey.Convey("GetSubtitle", t, func(ctx convey.C) {
  438. var (
  439. c = context.Background()
  440. oid = int64(0)
  441. subtitleID = int64(0)
  442. )
  443. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  444. testDao.GetSubtitle(c, oid, subtitleID)
  445. })
  446. })
  447. }
  448. func TestDaoTxUpdateSubtitle(t *testing.T) {
  449. convey.Convey("TxUpdateSubtitle", t, func(ctx convey.C) {
  450. var (
  451. tx, _ = testDao.BeginTran(c)
  452. subtitle = &model.Subtitle{}
  453. )
  454. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  455. testDao.TxUpdateSubtitle(tx, subtitle)
  456. })
  457. ctx.Reset(func() {
  458. tx.Commit()
  459. })
  460. })
  461. }
  462. func TestDaoTxAddSubtitlePub(t *testing.T) {
  463. convey.Convey("TxAddSubtitlePub", t, func(ctx convey.C) {
  464. var (
  465. tx, _ = testDao.BeginTran(c)
  466. subtitlePub = &model.SubtitlePub{}
  467. )
  468. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  469. testDao.TxAddSubtitlePub(tx, subtitlePub)
  470. })
  471. ctx.Reset(func() {
  472. tx.Commit()
  473. })
  474. })
  475. }
  476. func TestDaoMaskMids(t *testing.T) {
  477. convey.Convey("MaskMids", t, func(ctx convey.C) {
  478. var (
  479. c = context.Background()
  480. )
  481. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  482. mids, err := testDao.MaskMids(c)
  483. ctx.Convey("Then err should be nil.mids should not be nil.", func(ctx convey.C) {
  484. ctx.So(err, convey.ShouldBeNil)
  485. ctx.So(mids, convey.ShouldNotBeNil)
  486. })
  487. })
  488. })
  489. }