mysql_test.go 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package fav
  2. import (
  3. "context"
  4. favmdl "go-common/app/service/main/favorite/model"
  5. xtime "go-common/library/time"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestFavcntHit(t *testing.T) {
  10. convey.Convey("cntHit", t, func(ctx convey.C) {
  11. var (
  12. mid = int64(0)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. p1 := cntHit(mid)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestFavfolderHit(t *testing.T) {
  23. convey.Convey("folderHit", t, func(ctx convey.C) {
  24. var (
  25. mid = int64(1)
  26. )
  27. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  28. p1 := folderHit(mid)
  29. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  30. ctx.So(p1, convey.ShouldNotBeNil)
  31. })
  32. })
  33. })
  34. }
  35. func TestFavrelationHit(t *testing.T) {
  36. convey.Convey("relationHit", t, func(ctx convey.C) {
  37. var (
  38. mid = int64(0)
  39. )
  40. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  41. p1 := relationHit(mid)
  42. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  43. ctx.So(p1, convey.ShouldNotBeNil)
  44. })
  45. })
  46. })
  47. }
  48. func TestFavusersHit(t *testing.T) {
  49. convey.Convey("usersHit", t, func(ctx convey.C) {
  50. var (
  51. oid = int64(0)
  52. )
  53. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  54. p1 := usersHit(oid)
  55. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  56. ctx.So(p1, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestFavPingMySQL(t *testing.T) {
  62. convey.Convey("PingMySQL", t, func(ctx convey.C) {
  63. var (
  64. c = context.Background()
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. err := d.pingMySQL(c)
  68. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldBeNil)
  70. })
  71. })
  72. })
  73. }
  74. func TestRecentFolder(t *testing.T) {
  75. convey.Convey("Folder Recents", t, func(ctx convey.C) {
  76. var (
  77. c = context.Background()
  78. mid = int64(0)
  79. fid = int64(0)
  80. )
  81. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  82. _, err := d.RecentRes(c, mid, fid)
  83. ctx.So(err, convey.ShouldBeNil)
  84. })
  85. })
  86. }
  87. func TestUpdateFavSequence(t *testing.T) {
  88. convey.Convey("Test Update Sequence", t, func(ctx convey.C) {
  89. var (
  90. c = context.Background()
  91. mid = int64(0)
  92. fid = int64(0)
  93. )
  94. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  95. t, err := d.BeginTran(c)
  96. ctx.So(err, convey.ShouldBeNil)
  97. _, err = d.TxUpdateFavSequence(t, mid, fid, 1, 2, 123, xtime.Time(0))
  98. ctx.So(err, convey.ShouldBeNil)
  99. })
  100. })
  101. }
  102. func TestFavFolder(t *testing.T) {
  103. convey.Convey("Folder", t, func(ctx convey.C) {
  104. var (
  105. c = context.Background()
  106. tp = int8(0)
  107. mid = int64(0)
  108. fid = int64(0)
  109. )
  110. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  111. _, err := d.Folder(c, tp, mid, fid)
  112. ctx.Convey("Then err should be nil.f should not be nil.", func(ctx convey.C) {
  113. ctx.So(err, convey.ShouldBeNil)
  114. })
  115. })
  116. })
  117. }
  118. func TestFavUpFolderCnt(t *testing.T) {
  119. convey.Convey("UpFolderCnt", t, func(ctx convey.C) {
  120. var (
  121. c = context.Background()
  122. mid = int64(0)
  123. fid = int64(0)
  124. cnt = int(0)
  125. now xtime.Time
  126. )
  127. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  128. rows, err := d.UpFolderCnt(c, mid, fid, cnt, now)
  129. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  130. ctx.So(err, convey.ShouldBeNil)
  131. ctx.So(rows, convey.ShouldNotBeNil)
  132. })
  133. })
  134. })
  135. }
  136. func TestFavRelation(t *testing.T) {
  137. convey.Convey("Relation", t, func(ctx convey.C) {
  138. var (
  139. c = context.Background()
  140. tp = int8(0)
  141. mid = int64(0)
  142. fid = int64(0)
  143. oid = int64(0)
  144. )
  145. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  146. _, err := d.Relation(c, tp, mid, fid, oid)
  147. ctx.Convey("Then err should be nil.m should not be nil.", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. })
  150. })
  151. })
  152. }
  153. func TestFavRelations(t *testing.T) {
  154. convey.Convey("Relations", t, func(ctx convey.C) {
  155. var (
  156. c = context.Background()
  157. typ = int8(0)
  158. mid = int64(0)
  159. fid = int64(0)
  160. mtime xtime.Time
  161. limit = int(0)
  162. )
  163. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  164. fr, err := d.Relations(c, typ, mid, fid, mtime, limit)
  165. ctx.Convey("Then err should be nil.fr should not be nil.", func(ctx convey.C) {
  166. ctx.So(err, convey.ShouldBeNil)
  167. ctx.So(fr, convey.ShouldNotBeNil)
  168. })
  169. })
  170. })
  171. }
  172. func TestFavRelationFidsByOid(t *testing.T) {
  173. convey.Convey("RelationFidsByOid", t, func(ctx convey.C) {
  174. var (
  175. c = context.Background()
  176. tp = int8(0)
  177. mid = int64(0)
  178. oid = int64(0)
  179. )
  180. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  181. _, err := d.RelationFidsByOid(c, tp, mid, oid)
  182. ctx.Convey("Then err should be nil.fids should not be nil.", func(ctx convey.C) {
  183. ctx.So(err, convey.ShouldBeNil)
  184. })
  185. })
  186. })
  187. }
  188. func TestFavRelationCnt(t *testing.T) {
  189. convey.Convey("RelationCnt", t, func(ctx convey.C) {
  190. var (
  191. c = context.Background()
  192. mid = int64(0)
  193. fid = int64(0)
  194. )
  195. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  196. cnt, err := d.RelationCnt(c, mid, fid)
  197. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  198. ctx.So(err, convey.ShouldBeNil)
  199. ctx.So(cnt, convey.ShouldNotBeNil)
  200. })
  201. })
  202. })
  203. }
  204. func TestFavAddRelation(t *testing.T) {
  205. convey.Convey("AddRelation", t, func(ctx convey.C) {
  206. var (
  207. c = context.Background()
  208. fr = &favmdl.Favorite{}
  209. )
  210. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  211. rows, err := d.AddRelation(c, fr)
  212. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  213. ctx.So(err, convey.ShouldBeNil)
  214. ctx.So(rows, convey.ShouldNotBeNil)
  215. })
  216. })
  217. })
  218. }
  219. func TestFavDelRelation(t *testing.T) {
  220. convey.Convey("DelRelation", t, func(ctx convey.C) {
  221. var (
  222. c = context.Background()
  223. tp = int8(0)
  224. mid = int64(0)
  225. fid = int64(0)
  226. oid = int64(0)
  227. now xtime.Time
  228. )
  229. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  230. rows, err := d.DelRelation(c, tp, mid, fid, oid, now)
  231. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  232. ctx.So(err, convey.ShouldBeNil)
  233. ctx.So(rows, convey.ShouldNotBeNil)
  234. })
  235. })
  236. })
  237. }
  238. func TestFavUpStatCnt(t *testing.T) {
  239. convey.Convey("UpStatCnt", t, func(ctx convey.C) {
  240. var (
  241. c = context.Background()
  242. tp = int8(0)
  243. oid = int64(0)
  244. incr = int(0)
  245. now xtime.Time
  246. )
  247. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  248. rows, err := d.UpStatCnt(c, tp, oid, incr, now)
  249. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  250. ctx.So(err, convey.ShouldBeNil)
  251. ctx.So(rows, convey.ShouldNotBeNil)
  252. })
  253. })
  254. })
  255. }
  256. func TestFavStatCnt(t *testing.T) {
  257. convey.Convey("StatCnt", t, func(ctx convey.C) {
  258. var (
  259. c = context.Background()
  260. tp = int8(0)
  261. oid = int64(0)
  262. )
  263. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  264. cnt, err := d.StatCnt(c, tp, oid)
  265. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  266. ctx.So(err, convey.ShouldBeNil)
  267. ctx.So(cnt, convey.ShouldNotBeNil)
  268. })
  269. })
  270. })
  271. }
  272. func TestFavRelationFids(t *testing.T) {
  273. convey.Convey("RelationFids", t, func(ctx convey.C) {
  274. var (
  275. c = context.Background()
  276. tp = int8(0)
  277. mid = int64(0)
  278. )
  279. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  280. rfids, err := d.RelationFids(c, tp, mid)
  281. ctx.Convey("Then err should be nil.rfids should not be nil.", func(ctx convey.C) {
  282. ctx.So(err, convey.ShouldBeNil)
  283. ctx.So(rfids, convey.ShouldNotBeNil)
  284. })
  285. })
  286. })
  287. }
  288. func TestFavOidsByFid(t *testing.T) {
  289. convey.Convey("OidsByFid", t, func(ctx convey.C) {
  290. var (
  291. c = context.Background()
  292. typ = int8(0)
  293. mid = int64(0)
  294. fid = int64(0)
  295. offset = int(0)
  296. limit = int(0)
  297. )
  298. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  299. oids, err := d.OidsByFid(c, typ, mid, fid, offset, limit)
  300. ctx.Convey("Then err should be nil.oids should not be nil.", func(ctx convey.C) {
  301. ctx.So(err, convey.ShouldBeNil)
  302. ctx.So(oids, convey.ShouldNotBeNil)
  303. })
  304. })
  305. })
  306. }
  307. func TestFavDelRelationsByOids(t *testing.T) {
  308. convey.Convey("DelRelationsByOids", t, func(ctx convey.C) {
  309. var (
  310. c = context.Background()
  311. typ = int8(0)
  312. mid = int64(0)
  313. fid = int64(0)
  314. oids = []int64{}
  315. now xtime.Time
  316. )
  317. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  318. rows, err := d.DelRelationsByOids(c, typ, mid, fid, oids, now)
  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. }
  326. func TestFavAddUser(t *testing.T) {
  327. convey.Convey("AddUser", t, func(ctx convey.C) {
  328. var (
  329. c = context.Background()
  330. u = &favmdl.User{}
  331. )
  332. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  333. rows, err := d.AddUser(c, u)
  334. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  335. ctx.So(err, convey.ShouldBeNil)
  336. ctx.So(rows, convey.ShouldNotBeNil)
  337. })
  338. })
  339. })
  340. }
  341. func TestFavDelUser(t *testing.T) {
  342. convey.Convey("DelUser", t, func(ctx convey.C) {
  343. var (
  344. c = context.Background()
  345. u = &favmdl.User{}
  346. )
  347. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  348. rows, err := d.DelUser(c, u)
  349. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  350. ctx.So(err, convey.ShouldBeNil)
  351. ctx.So(rows, convey.ShouldNotBeNil)
  352. })
  353. })
  354. })
  355. }
  356. func TestRelationsByOids(t *testing.T) {
  357. convey.Convey("RelationsByOids", t, func(ctx convey.C) {
  358. var (
  359. c = context.Background()
  360. )
  361. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  362. favs, err := d.RelationsByOids(c, 2, 1501, 168, []int64{10108138})
  363. ctx.So(err, convey.ShouldBeNil)
  364. ctx.So(favs, convey.ShouldNotBeNil)
  365. _, err = d.BatchUpdateSeq(c, 76, favs)
  366. ctx.So(err, convey.ShouldBeNil)
  367. })
  368. })
  369. }