mysql_test.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/relation/model"
  5. "go-common/app/service/main/relation/model/i64b"
  6. "math/rand"
  7. "testing"
  8. "time"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func init() {
  12. rand.Seed(time.Now().UnixNano())
  13. }
  14. var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
  15. func RandStringRunes(n int) string {
  16. b := make([]rune, n)
  17. for i := range b {
  18. b[i] = letterRunes[rand.Intn(len(letterRunes))]
  19. }
  20. return string(b)
  21. }
  22. func TestDaohit(t *testing.T) {
  23. var (
  24. id = int64(1)
  25. )
  26. convey.Convey("hit", t, func(cv convey.C) {
  27. p1 := hit(id)
  28. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  29. cv.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. }
  33. func TestDaostatHit(t *testing.T) {
  34. var (
  35. id = int64(1)
  36. )
  37. convey.Convey("statHit", t, func(cv convey.C) {
  38. p1 := statHit(id)
  39. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  40. cv.So(p1, convey.ShouldNotBeNil)
  41. })
  42. })
  43. }
  44. func TestDaotagHit(t *testing.T) {
  45. var (
  46. id = int64(1)
  47. )
  48. convey.Convey("tagHit", t, func(cv convey.C) {
  49. p1 := tagHit(id)
  50. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  51. cv.So(p1, convey.ShouldNotBeNil)
  52. })
  53. })
  54. }
  55. func TestDaotagUserHit(t *testing.T) {
  56. var (
  57. id = int64(1)
  58. )
  59. convey.Convey("tagUserHit", t, func(cv convey.C) {
  60. p1 := tagUserHit(id)
  61. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  62. cv.So(p1, convey.ShouldNotBeNil)
  63. })
  64. })
  65. }
  66. func TestDaoBeginTran(t *testing.T) {
  67. var (
  68. c = context.Background()
  69. )
  70. convey.Convey("BeginTran", t, func(cv convey.C) {
  71. p1, err := d.BeginTran(c)
  72. cv.Convey("Then err should be nil.p1 should not be nil.", func(cv convey.C) {
  73. cv.So(err, convey.ShouldBeNil)
  74. cv.So(p1, convey.ShouldNotBeNil)
  75. })
  76. p1.Commit()
  77. })
  78. }
  79. func TestDaoFollowings(t *testing.T) {
  80. var (
  81. c = context.Background()
  82. tx, _ = d.BeginTran(c)
  83. mid = int64(1)
  84. fid = int64(2)
  85. mask = uint32(2)
  86. source = uint8(1)
  87. now = time.Now()
  88. )
  89. convey.Convey("Followings", t, func(cv convey.C) {
  90. affected, err := d.TxAddFollowing(c, tx, mid, fid, mask, source, now)
  91. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  92. cv.So(err, convey.ShouldBeNil)
  93. cv.So(affected, convey.ShouldNotBeNil)
  94. })
  95. tx.Commit()
  96. res, err := d.Followings(c, mid)
  97. cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
  98. cv.So(err, convey.ShouldBeNil)
  99. cv.So(res, convey.ShouldNotBeNil)
  100. })
  101. })
  102. }
  103. func TestDaoFollowingsIn(t *testing.T) {
  104. var (
  105. c = context.Background()
  106. mid = int64(1)
  107. fids = []int64{1, 2}
  108. )
  109. convey.Convey("FollowingsIn", t, func(cv convey.C) {
  110. res, err := d.FollowingsIn(c, mid, fids)
  111. cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
  112. cv.So(err, convey.ShouldBeNil)
  113. cv.So(res, convey.ShouldNotBeNil)
  114. })
  115. })
  116. }
  117. func TestDaoTxSetFollowing(t *testing.T) {
  118. var (
  119. c = context.Background()
  120. tx, _ = d.BeginTran(c)
  121. mid = int64(1)
  122. fid = int64(2)
  123. attribute = uint32(2)
  124. source = uint8(1)
  125. status = int(0)
  126. now = time.Now()
  127. )
  128. convey.Convey("TxSetFollowing", t, func(cv convey.C) {
  129. affected, err := d.TxSetFollowing(c, tx, mid, fid, attribute, source, status, now)
  130. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  131. cv.So(err, convey.ShouldBeNil)
  132. cv.So(affected, convey.ShouldNotBeNil)
  133. })
  134. tx.Commit()
  135. })
  136. }
  137. func TestDaoFollowers(t *testing.T) {
  138. var (
  139. c = context.Background()
  140. mid = int64(1)
  141. )
  142. convey.Convey("Followers", t, func(cv convey.C) {
  143. res, err := d.Followers(c, mid)
  144. cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
  145. cv.So(err, convey.ShouldBeNil)
  146. cv.So(res, convey.ShouldNotBeNil)
  147. })
  148. })
  149. }
  150. func TestDaoTxAddFollower(t *testing.T) {
  151. var (
  152. c = context.Background()
  153. tx, _ = d.BeginTran(c)
  154. mid = int64(1)
  155. fid = int64(2)
  156. mask = uint32(2)
  157. source = uint8(1)
  158. now = time.Now()
  159. )
  160. convey.Convey("TxAddFollower", t, func(cv convey.C) {
  161. affected, err := d.TxAddFollower(c, tx, mid, fid, mask, source, now)
  162. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  163. cv.So(err, convey.ShouldBeNil)
  164. cv.So(affected, convey.ShouldNotBeNil)
  165. })
  166. tx.Commit()
  167. })
  168. }
  169. func TestDaoTxSetFollower(t *testing.T) {
  170. var (
  171. c = context.Background()
  172. tx, _ = d.BeginTran(c)
  173. mid = int64(1)
  174. fid = int64(2)
  175. attribute = uint32(2)
  176. source = uint8(1)
  177. status = int(0)
  178. now = time.Now()
  179. )
  180. convey.Convey("TxSetFollower", t, func(cv convey.C) {
  181. affected, err := d.TxSetFollower(c, tx, mid, fid, attribute, source, status, now)
  182. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  183. cv.So(err, convey.ShouldBeNil)
  184. cv.So(affected, convey.ShouldNotBeNil)
  185. })
  186. tx.Commit()
  187. })
  188. }
  189. func TestDaoStat(t *testing.T) {
  190. var (
  191. c = context.Background()
  192. mid = int64(1)
  193. )
  194. convey.Convey("Stat", t, func(cv convey.C) {
  195. stat, err := d.Stat(c, mid)
  196. cv.Convey("Then err should be nil.stat should not be nil.", func(cv convey.C) {
  197. cv.So(err, convey.ShouldBeNil)
  198. cv.So(stat, convey.ShouldNotBeNil)
  199. })
  200. })
  201. }
  202. func TestDaoTxStat(t *testing.T) {
  203. var (
  204. c = context.Background()
  205. tx, _ = d.BeginTran(c)
  206. mid = int64(1)
  207. )
  208. convey.Convey("TxStat", t, func(cv convey.C) {
  209. stat, err := d.TxStat(c, tx, mid)
  210. cv.Convey("Then err should be nil.stat should not be nil.", func(cv convey.C) {
  211. cv.So(err, convey.ShouldBeNil)
  212. cv.So(stat, convey.ShouldNotBeNil)
  213. })
  214. tx.Commit()
  215. })
  216. }
  217. func TestDaoAddStat(t *testing.T) {
  218. var (
  219. c = context.Background()
  220. mid = int64(1)
  221. stat = &model.Stat{
  222. Mid: 1,
  223. }
  224. now = time.Now()
  225. )
  226. convey.Convey("AddStat", t, func(cv convey.C) {
  227. affected, err := d.AddStat(c, mid, stat, now)
  228. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  229. cv.So(err, convey.ShouldBeNil)
  230. cv.So(affected, convey.ShouldNotBeNil)
  231. })
  232. })
  233. }
  234. func TestDaoTxAddStat(t *testing.T) {
  235. var (
  236. c = context.Background()
  237. tx, _ = d.BeginTran(c)
  238. mid = int64(1)
  239. stat = &model.Stat{
  240. Mid: 1,
  241. }
  242. now = time.Now()
  243. )
  244. convey.Convey("TxAddStat", t, func(cv convey.C) {
  245. affected, err := d.TxAddStat(c, tx, mid, stat, now)
  246. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  247. cv.So(err, convey.ShouldBeNil)
  248. cv.So(affected, convey.ShouldNotBeNil)
  249. })
  250. tx.Commit()
  251. })
  252. }
  253. func TestDaoTxSetStat(t *testing.T) {
  254. var (
  255. c = context.Background()
  256. tx, _ = d.BeginTran(c)
  257. mid = int64(1)
  258. stat = &model.Stat{
  259. Mid: 1,
  260. }
  261. now = time.Now()
  262. )
  263. convey.Convey("TxSetStat", t, func(cv convey.C) {
  264. affected, err := d.TxSetStat(c, tx, mid, stat, now)
  265. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  266. cv.So(err, convey.ShouldBeNil)
  267. cv.So(affected, convey.ShouldNotBeNil)
  268. })
  269. tx.Commit()
  270. })
  271. }
  272. func TestDaoRelation(t *testing.T) {
  273. var (
  274. c = context.Background()
  275. mid = int64(1)
  276. fid = int64(2)
  277. )
  278. convey.Convey("Relation", t, func(cv convey.C) {
  279. attr, err := d.Relation(c, mid, fid)
  280. cv.Convey("Then err should be nil.attr should not be nil.", func(cv convey.C) {
  281. cv.So(err, convey.ShouldBeNil)
  282. cv.So(attr, convey.ShouldNotBeNil)
  283. })
  284. })
  285. }
  286. func TestDaoLoadMonitor(t *testing.T) {
  287. var (
  288. c = context.Background()
  289. )
  290. convey.Convey("LoadMonitor", t, func(cv convey.C) {
  291. affected, err := d.AddMonitor(c, 1, time.Now())
  292. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  293. cv.So(err, convey.ShouldBeNil)
  294. cv.So(affected, convey.ShouldNotBeNil)
  295. })
  296. mids, err := d.LoadMonitor(c)
  297. cv.Convey("Then err should be nil.mids should not be nil.", func(cv convey.C) {
  298. cv.So(err, convey.ShouldBeNil)
  299. cv.So(mids, convey.ShouldNotBeNil)
  300. })
  301. })
  302. }
  303. func TestDaoDelMonitor(t *testing.T) {
  304. var (
  305. c = context.Background()
  306. mid = int64(1)
  307. )
  308. convey.Convey("DelMonitor", t, func(cv convey.C) {
  309. affected, err := d.DelMonitor(c, mid)
  310. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  311. cv.So(err, convey.ShouldBeNil)
  312. cv.So(affected, convey.ShouldNotBeNil)
  313. })
  314. })
  315. }
  316. func TestDaoTxDelTagUser(t *testing.T) {
  317. var (
  318. c = context.Background()
  319. tx, _ = d.BeginTran(c)
  320. mid = int64(1)
  321. fid = int64(2)
  322. )
  323. convey.Convey("TxDelTagUser", t, func(cv convey.C) {
  324. affected, err := d.TxDelTagUser(c, tx, mid, fid)
  325. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  326. cv.So(err, convey.ShouldBeNil)
  327. cv.So(affected, convey.ShouldNotBeNil)
  328. })
  329. tx.Commit()
  330. })
  331. }
  332. func TestDaoTags(t *testing.T) {
  333. var (
  334. c = context.Background()
  335. mid = int64(1)
  336. )
  337. convey.Convey("Tags", t, func(cv convey.C) {
  338. res, err := d.Tags(c, mid)
  339. cv.Convey("Then err should be nil.res should not be nil.", func(cv convey.C) {
  340. cv.So(err, convey.ShouldBeNil)
  341. cv.So(res, convey.ShouldNotBeNil)
  342. })
  343. })
  344. }
  345. func TestDaoDelTag(t *testing.T) {
  346. var (
  347. c = context.Background()
  348. mid = int64(1)
  349. id = int64(2)
  350. )
  351. convey.Convey("DelTag", t, func(cv convey.C) {
  352. affected, err := d.DelTag(c, mid, id)
  353. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  354. cv.So(err, convey.ShouldBeNil)
  355. cv.So(affected, convey.ShouldNotBeNil)
  356. })
  357. })
  358. }
  359. func TestDaoSetTagName(t *testing.T) {
  360. var (
  361. c = context.Background()
  362. id = int64(1)
  363. mid = int64(2)
  364. name = "test"
  365. now = time.Now()
  366. )
  367. convey.Convey("SetTagName", t, func(cv convey.C) {
  368. affected, err := d.SetTagName(c, id, mid, name, now)
  369. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  370. cv.So(err, convey.ShouldBeNil)
  371. cv.So(affected, convey.ShouldNotBeNil)
  372. })
  373. })
  374. }
  375. func TestDaoTagUserByMidFid(t *testing.T) {
  376. var (
  377. c = context.Background()
  378. mid = int64(1)
  379. fid = int64(2)
  380. )
  381. convey.Convey("TagUserByMidFid", t, func(cv convey.C) {
  382. lastID, err := d.AddTag(c, mid, fid, "test"+RandStringRunes(5), time.Now())
  383. cv.Convey("AddTag; Then err should be nil.lastID should not be nil.", func(cv convey.C) {
  384. cv.So(err, convey.ShouldBeNil)
  385. cv.So(lastID, convey.ShouldNotBeNil)
  386. })
  387. tids := i64b.Int64Bytes([]int64{lastID})
  388. affected, err := d.SetTagUser(c, mid, fid, tids, time.Now())
  389. cv.Convey("SetTagUser; Then err should be nil.affected should not be nil.", func(cv convey.C) {
  390. cv.So(err, convey.ShouldBeNil)
  391. cv.So(affected, convey.ShouldNotBeNil)
  392. })
  393. affected2, err := d.AddTagUser(c, mid, fid, tids, time.Now())
  394. cv.Convey("AddTagUser; Then err should be nil.affected should not be nil.", func(cv convey.C) {
  395. cv.So(err, convey.ShouldBeNil)
  396. cv.So(affected2, convey.ShouldNotBeNil)
  397. })
  398. tag1, err := d.TagUserByMidFid(c, mid, fid)
  399. cv.Convey("TagUserByMidFid; Then err should be nil.tag1 should not be nil.", func(cv convey.C) {
  400. cv.So(err, convey.ShouldBeNil)
  401. cv.So(tag1, convey.ShouldNotBeNil)
  402. })
  403. tags2, err := d.UsersTags(c, mid, []int64{fid})
  404. cv.Convey("UsersTags; Then err should be nil.tags2 should not be nil.", func(cv convey.C) {
  405. cv.So(err, convey.ShouldBeNil)
  406. cv.So(tags2, convey.ShouldNotBeNil)
  407. })
  408. tags3, err := d.UserTag(c, mid)
  409. cv.Convey("UserTag; Then err should be nil.tags3 should not be nil.", func(cv convey.C) {
  410. cv.So(err, convey.ShouldBeNil)
  411. cv.So(tags3, convey.ShouldNotBeNil)
  412. })
  413. })
  414. }
  415. func TestDaoHasReachAchieve(t *testing.T) {
  416. var (
  417. c = context.Background()
  418. mid = int64(1)
  419. achieve model.AchieveFlag
  420. )
  421. convey.Convey("HasReachAchieve", t, func(cv convey.C) {
  422. p1 := d.HasReachAchieve(c, mid, achieve)
  423. cv.Convey("Then p1 should not be nil.", func(cv convey.C) {
  424. cv.So(p1, convey.ShouldNotBeNil)
  425. })
  426. })
  427. }
  428. func TestDaoFollowerNotifySetting(t *testing.T) {
  429. var (
  430. c = context.Background()
  431. mid = int64(1)
  432. )
  433. convey.Convey("FollowerNotifySetting", t, func(cv convey.C) {
  434. p1, err := d.FollowerNotifySetting(c, mid)
  435. cv.Convey("Then err should be nil.p1 should not be nil.", func(cv convey.C) {
  436. cv.So(err, convey.ShouldBeNil)
  437. cv.So(p1, convey.ShouldNotBeNil)
  438. })
  439. })
  440. }
  441. func TestDaoEnableFollowerNotify(t *testing.T) {
  442. var (
  443. c = context.Background()
  444. mid = int64(1)
  445. )
  446. convey.Convey("EnableFollowerNotify", t, func(cv convey.C) {
  447. affected, err := d.EnableFollowerNotify(c, mid)
  448. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  449. cv.So(err, convey.ShouldBeNil)
  450. cv.So(affected, convey.ShouldNotBeNil)
  451. })
  452. })
  453. }
  454. func TestDaoDisableFollowerNotify(t *testing.T) {
  455. var (
  456. c = context.Background()
  457. mid = int64(1)
  458. )
  459. convey.Convey("DisableFollowerNotify", t, func(cv convey.C) {
  460. affected, err := d.DisableFollowerNotify(c, mid)
  461. cv.Convey("Then err should be nil.affected should not be nil.", func(cv convey.C) {
  462. cv.So(err, convey.ShouldBeNil)
  463. cv.So(affected, convey.ShouldNotBeNil)
  464. })
  465. })
  466. }