mysql_test.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/member/model"
  6. "go-common/library/time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaohit(t *testing.T) {
  10. var (
  11. id = int64(0)
  12. )
  13. convey.Convey("hit", t, func(ctx convey.C) {
  14. p1 := hit(id)
  15. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestDaoBeginTran(t *testing.T) {
  21. var (
  22. c = context.Background()
  23. )
  24. convey.Convey("BeginTran", t, func(ctx convey.C) {
  25. tx, err := d.BeginTran(c)
  26. defer tx.Commit()
  27. ctx.Convey("Error should be nil", func(ctx convey.C) {
  28. ctx.So(err, convey.ShouldBeNil)
  29. })
  30. ctx.Convey("tx should not be nil", func(ctx convey.C) {
  31. ctx.So(tx, convey.ShouldNotBeNil)
  32. })
  33. })
  34. }
  35. func TestDaoBaseInfo(t *testing.T) {
  36. var (
  37. c = context.Background()
  38. mid = int64(0)
  39. )
  40. convey.Convey("BaseInfo", t, func(ctx convey.C) {
  41. r, err := d.BaseInfo(c, mid)
  42. ctx.Convey("Error should be nil", func(ctx convey.C) {
  43. ctx.So(err, convey.ShouldBeNil)
  44. })
  45. ctx.Convey("r should not be nil", func(ctx convey.C) {
  46. ctx.So(r, convey.ShouldNotBeNil)
  47. })
  48. })
  49. }
  50. func TestDaoSetBase(t *testing.T) {
  51. var (
  52. c = context.Background()
  53. base = &model.BaseInfo{
  54. Mid: 0,
  55. }
  56. )
  57. convey.Convey("SetBase", t, func(ctx convey.C) {
  58. err := d.SetBase(c, base)
  59. ctx.Convey("Error should be nil", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldBeNil)
  61. })
  62. })
  63. }
  64. func TestDaoSetSign(t *testing.T) {
  65. var (
  66. c = context.Background()
  67. mid = int64(0)
  68. sign = "test"
  69. )
  70. convey.Convey("SetSign", t, func(ctx convey.C) {
  71. err := d.SetSign(c, mid, sign)
  72. ctx.Convey("Error should be nil", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. })
  75. })
  76. }
  77. func TestDaoSetName(t *testing.T) {
  78. var (
  79. c = context.Background()
  80. mid = int64(0)
  81. name = "test"
  82. )
  83. convey.Convey("SetName", t, func(ctx convey.C) {
  84. err := d.SetName(c, mid, name)
  85. ctx.Convey("Error should be nil", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. })
  88. })
  89. }
  90. func TestDaoSetRank(t *testing.T) {
  91. var (
  92. c = context.Background()
  93. mid = int64(0)
  94. rank = int64(100)
  95. )
  96. convey.Convey("SetRank", t, func(ctx convey.C) {
  97. err := d.SetRank(c, mid, rank)
  98. ctx.Convey("Error should be nil", func(ctx convey.C) {
  99. ctx.So(err, convey.ShouldBeNil)
  100. })
  101. })
  102. }
  103. func TestDaoSetSex(t *testing.T) {
  104. var (
  105. c = context.Background()
  106. mid = int64(0)
  107. sex = int64(1)
  108. )
  109. convey.Convey("SetSex", t, func(ctx convey.C) {
  110. err := d.SetSex(c, mid, sex)
  111. ctx.Convey("Error should be nil", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. })
  114. })
  115. }
  116. func TestDaoSetBirthday(t *testing.T) {
  117. var (
  118. c = context.Background()
  119. mid = int64(0)
  120. birthday = time.Time(946656000)
  121. )
  122. convey.Convey("SetBirthday", t, func(ctx convey.C) {
  123. err := d.SetBirthday(c, mid, birthday)
  124. ctx.Convey("Error should be nil", func(ctx convey.C) {
  125. ctx.So(err, convey.ShouldBeNil)
  126. })
  127. })
  128. }
  129. func TestDaoSetFace(t *testing.T) {
  130. var (
  131. c = context.Background()
  132. mid = int64(0)
  133. face = "test"
  134. )
  135. convey.Convey("SetFace", t, func(ctx convey.C) {
  136. err := d.SetFace(c, mid, face)
  137. ctx.Convey("Error should be nil", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. })
  140. })
  141. }
  142. func TestDaoExpDB(t *testing.T) {
  143. var (
  144. c = context.Background()
  145. mid = int64(0)
  146. )
  147. convey.Convey("ExpDB", t, func(ctx convey.C) {
  148. count, err := d.ExpDB(c, mid)
  149. ctx.Convey("Error should be nil", func(ctx convey.C) {
  150. ctx.So(err, convey.ShouldBeNil)
  151. })
  152. ctx.Convey("count should not be nil", func(ctx convey.C) {
  153. ctx.So(count, convey.ShouldNotBeNil)
  154. })
  155. })
  156. }
  157. func TestDaoSetExp(t *testing.T) {
  158. var (
  159. c = context.Background()
  160. mid = int64(0)
  161. count = int64(10)
  162. )
  163. convey.Convey("SetExp", t, func(ctx convey.C) {
  164. affect, err := d.SetExp(c, mid, count)
  165. ctx.Convey("Error should be nil", func(ctx convey.C) {
  166. ctx.So(err, convey.ShouldBeNil)
  167. })
  168. ctx.Convey("affect should not be nil", func(ctx convey.C) {
  169. ctx.So(affect, convey.ShouldNotBeNil)
  170. })
  171. })
  172. }
  173. func TestDaoUpdateExp(t *testing.T) {
  174. var (
  175. c = context.Background()
  176. mid = int64(0)
  177. delta = int64(6)
  178. )
  179. convey.Convey("UpdateExp", t, func(ctx convey.C) {
  180. affect, err := d.UpdateExp(c, mid, delta)
  181. ctx.Convey("Error should be nil", func(ctx convey.C) {
  182. ctx.So(err, convey.ShouldBeNil)
  183. })
  184. ctx.Convey("affect should not be nil", func(ctx convey.C) {
  185. ctx.So(affect, convey.ShouldNotBeNil)
  186. })
  187. })
  188. }
  189. func TestDaoUserAttrDB(t *testing.T) {
  190. var (
  191. c = context.Background()
  192. mid = int64(0)
  193. attr uint
  194. )
  195. convey.Convey("UserAttrDB", t, func(ctx convey.C) {
  196. hasAttr, err := d.UserAttrDB(c, mid, attr)
  197. ctx.Convey("Error should be nil", func(ctx convey.C) {
  198. ctx.So(err, convey.ShouldBeNil)
  199. })
  200. ctx.Convey("hasAttr should not be nil", func(ctx convey.C) {
  201. ctx.So(hasAttr, convey.ShouldNotBeNil)
  202. })
  203. })
  204. }
  205. func TestDaoSetUserAttr(t *testing.T) {
  206. var (
  207. c = context.Background()
  208. mid = int64(0)
  209. attr uint
  210. )
  211. convey.Convey("SetUserAttr", t, func(ctx convey.C) {
  212. err := d.SetUserAttr(c, mid, attr)
  213. ctx.Convey("Error should be nil", func(ctx convey.C) {
  214. ctx.So(err, convey.ShouldBeNil)
  215. })
  216. })
  217. }
  218. func TestDaoOfficials(t *testing.T) {
  219. var (
  220. c = context.Background()
  221. )
  222. convey.Convey("Officials", t, func(ctx convey.C) {
  223. om, err := d.Officials(c)
  224. ctx.Convey("Error should be nil", func(ctx convey.C) {
  225. ctx.So(err, convey.ShouldBeNil)
  226. })
  227. ctx.Convey("om should not be nil", func(ctx convey.C) {
  228. ctx.So(om, convey.ShouldNotBeNil)
  229. })
  230. })
  231. }
  232. func TestDaoOfficial(t *testing.T) {
  233. var (
  234. c = context.Background()
  235. mid = int64(1)
  236. )
  237. convey.Convey("Official", t, func(ctx convey.C) {
  238. p1, p2 := d.Official(c, mid)
  239. ctx.Convey("Error should be nil", func(ctx convey.C) {
  240. ctx.So(p2, convey.ShouldBeNil)
  241. })
  242. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  243. ctx.So(p1, convey.ShouldNotBeNil)
  244. })
  245. })
  246. }
  247. func TestDaoMoralDB(t *testing.T) {
  248. var (
  249. c = context.Background()
  250. mid = int64(4780461)
  251. )
  252. convey.Convey("MoralDB", t, func(ctx convey.C) {
  253. moral, err := d.MoralDB(c, mid)
  254. ctx.Convey("Error should be nil", func(ctx convey.C) {
  255. ctx.So(err, convey.ShouldBeNil)
  256. })
  257. ctx.Convey("moral should not be nil", func(ctx convey.C) {
  258. ctx.So(moral, convey.ShouldNotBeNil)
  259. })
  260. })
  261. }
  262. func TestDaoTxMoralDB(t *testing.T) {
  263. var (
  264. c = context.Background()
  265. tx, _ = d.db.Begin(c)
  266. mid = int64(8)
  267. )
  268. defer tx.Commit()
  269. convey.Convey("TxMoralDB", t, func(ctx convey.C) {
  270. moral, err := d.TxMoralDB(tx, mid)
  271. ctx.Convey("Error should be nil", func(ctx convey.C) {
  272. ctx.So(err, convey.ShouldBeNil)
  273. })
  274. ctx.Convey("moral should not be nil", func(ctx convey.C) {
  275. ctx.So(moral, convey.ShouldNotBeNil)
  276. })
  277. })
  278. }
  279. func TestDaoTxUpdateMoral(t *testing.T) {
  280. var (
  281. c = context.Background()
  282. tx, _ = d.db.Begin(c)
  283. mid = int64(0)
  284. moral = int64(0)
  285. added = int64(0)
  286. deducted = int64(0)
  287. )
  288. defer tx.Commit()
  289. convey.Convey("TxUpdateMoral", t, func(ctx convey.C) {
  290. err := d.TxUpdateMoral(tx, mid, moral, added, deducted)
  291. ctx.Convey("Error should be nil", func(ctx convey.C) {
  292. ctx.So(err, convey.ShouldBeNil)
  293. })
  294. })
  295. }
  296. func TestDaoTxUpdateMoralRecoverDate(t *testing.T) {
  297. var (
  298. c = context.Background()
  299. tx, _ = d.db.Begin(c)
  300. mid = int64(0)
  301. recoverDate = time.Time(946656000)
  302. )
  303. defer tx.Commit()
  304. convey.Convey("TxUpdateMoralRecoverDate", t, func(ctx convey.C) {
  305. err := d.TxUpdateMoralRecoverDate(tx, mid, recoverDate)
  306. ctx.Convey("Error should be nil", func(ctx convey.C) {
  307. ctx.So(err, convey.ShouldBeNil)
  308. })
  309. })
  310. }
  311. func TestDaoTxInitMoral(t *testing.T) {
  312. var (
  313. c = context.Background()
  314. tx, _ = d.db.Begin(c)
  315. mid = int64(10)
  316. moral = int64(0)
  317. added = int64(0)
  318. deducted = int64(0)
  319. lastRecoverDate = time.Time(946656000)
  320. )
  321. defer tx.Commit()
  322. convey.Convey("TxInitMoral", t, func(ctx convey.C) {
  323. err := d.TxInitMoral(tx, mid, moral, added, deducted, lastRecoverDate)
  324. ctx.Convey("Error should be nil", func(ctx convey.C) {
  325. ctx.So(err, convey.ShouldBeNil)
  326. })
  327. })
  328. }
  329. func TestDaoSetOfficialDoc(t *testing.T) {
  330. var (
  331. c = context.Background()
  332. od = &model.OfficialDoc{
  333. Mid: 4780461,
  334. }
  335. )
  336. convey.Convey("SetOfficialDoc", t, func(ctx convey.C) {
  337. err := d.SetOfficialDoc(c, od)
  338. ctx.Convey("Error should be nil", func(ctx convey.C) {
  339. ctx.So(err, convey.ShouldBeNil)
  340. })
  341. })
  342. }
  343. func TestDaoOfficialDoc(t *testing.T) {
  344. var (
  345. c = context.Background()
  346. mid = int64(4780461)
  347. )
  348. convey.Convey("OfficialDoc", t, func(ctx convey.C) {
  349. p1, p2 := d.OfficialDoc(c, mid)
  350. ctx.Convey("Error should be nil", func(ctx convey.C) {
  351. ctx.So(p2, convey.ShouldBeNil)
  352. })
  353. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  354. ctx.So(p1, convey.ShouldNotBeNil)
  355. })
  356. })
  357. }
  358. func TestDaoRealnameInfo(t *testing.T) {
  359. var (
  360. c = context.Background()
  361. mid = int64(46333)
  362. )
  363. convey.Convey("TestDaoRealnameInfo", t, func(ctx convey.C) {
  364. info, err := d.RealnameInfo(c, mid)
  365. ctx.Convey("Error should be nil", func(ctx convey.C) {
  366. ctx.So(err, convey.ShouldBeNil)
  367. })
  368. ctx.Convey("info should not be nil", func(ctx convey.C) {
  369. t.Logf("info:%+v", info)
  370. ctx.So(info, convey.ShouldNotBeNil)
  371. })
  372. })
  373. }
  374. func TestDaoRealnameInfoByCard(t *testing.T) {
  375. var (
  376. c = context.Background()
  377. cardMD5 = "0088bdb8af58d25c1d9864e568a3cfb8"
  378. )
  379. convey.Convey("TestDaoRealnameInfoByCard", t, func(ctx convey.C) {
  380. info, err := d.RealnameInfoByCard(c, cardMD5)
  381. ctx.Convey("Error should be nil", func(ctx convey.C) {
  382. ctx.So(err, convey.ShouldBeNil)
  383. })
  384. ctx.Convey("info should not be nil", func(ctx convey.C) {
  385. t.Logf("info:%+v", info)
  386. ctx.So(info, convey.ShouldNotBeNil)
  387. })
  388. })
  389. }
  390. func TestDaoRealnameApply(t *testing.T) {
  391. var (
  392. c = context.Background()
  393. mid = int64(4780461)
  394. )
  395. convey.Convey("RealnameApply", t, func(ctx convey.C) {
  396. apply, err := d.RealnameApply(c, mid)
  397. ctx.Convey("Error should be nil", func(ctx convey.C) {
  398. ctx.So(err, convey.ShouldBeNil)
  399. })
  400. ctx.Convey("apply should not be nil", func(ctx convey.C) {
  401. ctx.So(apply, convey.ShouldNotBeNil)
  402. })
  403. })
  404. }
  405. func TestDaoInsertRealnameApply(t *testing.T) {
  406. var (
  407. c = context.Background()
  408. data = &model.RealnameApply{
  409. MID: 4780461,
  410. }
  411. )
  412. convey.Convey("InsertRealnameApply", t, func(ctx convey.C) {
  413. err := d.InsertRealnameApply(c, data)
  414. ctx.Convey("Error should be nil", func(ctx convey.C) {
  415. ctx.So(err, convey.ShouldBeNil)
  416. })
  417. })
  418. }
  419. func TestDaoInsertRealnameApplyImg(t *testing.T) {
  420. var (
  421. c = context.Background()
  422. data = &model.RealnameApplyImage{
  423. ID: 1,
  424. IMGData: "1234",
  425. }
  426. )
  427. convey.Convey("InsertRealnameApplyImg", t, func(ctx convey.C) {
  428. id, err := d.InsertRealnameApplyImg(c, data)
  429. ctx.Convey("Error should be nil", func(ctx convey.C) {
  430. ctx.So(err, convey.ShouldBeNil)
  431. })
  432. ctx.Convey("id should not be nil", func(ctx convey.C) {
  433. ctx.So(id, convey.ShouldNotBeNil)
  434. })
  435. })
  436. }
  437. func TestDaoRealnameApplyIMG(t *testing.T) {
  438. var (
  439. c = context.Background()
  440. id = int(1)
  441. )
  442. convey.Convey("RealnameApplyIMG", t, func(ctx convey.C) {
  443. img, err := d.RealnameApplyIMG(c, id)
  444. ctx.Convey("Error should be nil", func(ctx convey.C) {
  445. ctx.So(err, convey.ShouldBeNil)
  446. })
  447. ctx.Convey("img should not be nil", func(ctx convey.C) {
  448. ctx.So(img, convey.ShouldNotBeNil)
  449. })
  450. })
  451. }
  452. func TestDaoInsertOldRealnameApply(t *testing.T) {
  453. var (
  454. c = context.Background()
  455. data = &model.RealnameApply{
  456. ID: 1,
  457. }
  458. )
  459. convey.Convey("InsertOldRealnameApply", t, func(ctx convey.C) {
  460. id, err := d.InsertOldRealnameApply(c, data)
  461. ctx.Convey("Error should be nil", func(ctx convey.C) {
  462. ctx.So(err, convey.ShouldBeNil)
  463. })
  464. ctx.Convey("id should not be nil", func(ctx convey.C) {
  465. ctx.So(id, convey.ShouldNotBeNil)
  466. })
  467. })
  468. }
  469. func TestDaoInsertOldRealnameApplyImg(t *testing.T) {
  470. var (
  471. c = context.Background()
  472. data = &model.RealnameApplyImage{
  473. ID: 1,
  474. IMGData: "1234",
  475. }
  476. )
  477. convey.Convey("InsertOldRealnameApplyImg", t, func(ctx convey.C) {
  478. id, err := d.InsertOldRealnameApplyImg(c, data)
  479. ctx.Convey("Error should be nil", func(ctx convey.C) {
  480. ctx.So(err, convey.ShouldBeNil)
  481. })
  482. ctx.Convey("id should not be nil", func(ctx convey.C) {
  483. ctx.So(id, convey.ShouldNotBeNil)
  484. })
  485. })
  486. }