mysql_test.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. package dao
  2. import (
  3. "context"
  4. // "database/sql"
  5. "go-common/app/job/main/coupon/model"
  6. "testing"
  7. "time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaohitInfo(t *testing.T) {
  11. convey.Convey("hitInfo", t, func(convCtx convey.C) {
  12. var (
  13. mid = int64(0)
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. p1 := hitInfo(mid)
  17. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(p1, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaohitChangeLog(t *testing.T) {
  24. convey.Convey("hitChangeLog", t, func(convCtx convey.C) {
  25. var (
  26. mid = int64(0)
  27. )
  28. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  29. p1 := hitChangeLog(mid)
  30. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  31. convCtx.So(p1, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestDaohitUser(t *testing.T) {
  37. convey.Convey("hitUser", t, func(convCtx convey.C) {
  38. var (
  39. mid = int64(0)
  40. )
  41. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  42. p1 := hitUser(mid)
  43. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  44. convCtx.So(p1, convey.ShouldNotBeNil)
  45. })
  46. })
  47. })
  48. }
  49. func TestDaohitUserLog(t *testing.T) {
  50. convey.Convey("hitUserLog", t, func(convCtx convey.C) {
  51. var (
  52. mid = int64(0)
  53. )
  54. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  55. p1 := hitUserLog(mid)
  56. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  57. convCtx.So(p1, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. // go test -test.v -test.run TestDaoUpdateCoupon
  63. func TestDaoUpdateCoupon(t *testing.T) {
  64. convey.Convey("UpdateCoupon", t, func(convCtx convey.C) {
  65. var (
  66. c = context.Background()
  67. tx, _ = d.BeginTran(context.Background())
  68. mid = int64(1)
  69. state = int8(1)
  70. useVer = int64(11)
  71. ver = int64(2)
  72. couponToken = "729792667120180402161647"
  73. )
  74. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  75. a, err := d.UpdateCoupon(c, tx, mid, state, useVer, ver, couponToken)
  76. if err == nil {
  77. if err = tx.Commit(); err != nil {
  78. tx.Rollback()
  79. }
  80. } else {
  81. tx.Rollback()
  82. }
  83. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  84. convCtx.So(err, convey.ShouldBeNil)
  85. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  86. })
  87. })
  88. })
  89. }
  90. func TestDaoCouponInfo(t *testing.T) {
  91. convey.Convey("CouponInfo", t, func(convCtx convey.C) {
  92. var (
  93. c = context.Background()
  94. mid = int64(0)
  95. token = ""
  96. )
  97. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  98. r, err := d.CouponInfo(c, mid, token)
  99. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  100. convCtx.So(err, convey.ShouldBeNil)
  101. convCtx.So(r, convey.ShouldNotBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestDaoCouponList(t *testing.T) {
  107. convey.Convey("CouponList", t, func(convCtx convey.C) {
  108. var (
  109. c = context.Background()
  110. index = int64(0)
  111. state = int8(0)
  112. no, _ = time.Parse("2006-01-02 15:04:05", "2018-12-27 17:28:51")
  113. )
  114. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  115. res, err := d.CouponList(c, index, state, no)
  116. convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
  117. convCtx.So(err, convey.ShouldBeNil)
  118. convCtx.So(res, convey.ShouldBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestDaoInsertPointHistory(t *testing.T) {
  124. convey.Convey("InsertPointHistory", t, func(convCtx convey.C) {
  125. var (
  126. c = context.Background()
  127. tx, _ = d.BeginTran(context.Background())
  128. l = &model.CouponChangeLog{}
  129. )
  130. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  131. a, err := d.InsertPointHistory(c, tx, l)
  132. if err == nil {
  133. if err = tx.Commit(); err != nil {
  134. tx.Rollback()
  135. }
  136. } else {
  137. tx.Rollback()
  138. }
  139. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  140. convCtx.So(err, convey.ShouldBeNil)
  141. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  142. })
  143. })
  144. })
  145. }
  146. func TestDaoBeginTran(t *testing.T) {
  147. convey.Convey("BeginTran", t, func(convCtx convey.C) {
  148. var (
  149. c = context.Background()
  150. )
  151. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  152. p1, err := d.BeginTran(c)
  153. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  154. convCtx.So(err, convey.ShouldBeNil)
  155. convCtx.So(p1, convey.ShouldNotBeNil)
  156. })
  157. })
  158. })
  159. }
  160. func TestDaoByOrderNo(t *testing.T) {
  161. convey.Convey("ByOrderNo", t, func(convCtx convey.C) {
  162. var (
  163. c = context.Background()
  164. orderNo = ""
  165. )
  166. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  167. r, err := d.ByOrderNo(c, orderNo)
  168. convCtx.Convey("Then err should be nil.r should be nil.", func(convCtx convey.C) {
  169. convCtx.So(err, convey.ShouldBeNil)
  170. convCtx.So(r, convey.ShouldBeNil)
  171. })
  172. })
  173. })
  174. }
  175. func TestDaoUpdateOrderState(t *testing.T) {
  176. convey.Convey("UpdateOrderState", t, func(convCtx convey.C) {
  177. var (
  178. c = context.Background()
  179. tx, _ = d.BeginTran(context.Background())
  180. mid = int64(0)
  181. state = int8(0)
  182. useVer = int64(0)
  183. ver = int64(0)
  184. orderNo = ""
  185. )
  186. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  187. a, err := d.UpdateOrderState(c, tx, mid, state, useVer, ver, orderNo)
  188. if err == nil {
  189. if err = tx.Commit(); err != nil {
  190. tx.Rollback()
  191. }
  192. } else {
  193. tx.Rollback()
  194. }
  195. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  196. convCtx.So(err, convey.ShouldBeNil)
  197. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  198. })
  199. })
  200. })
  201. }
  202. func TestDaoAddOrderLog(t *testing.T) {
  203. convey.Convey("AddOrderLog", t, func(convCtx convey.C) {
  204. var (
  205. c = context.Background()
  206. tx, _ = d.BeginTran(context.Background())
  207. o = &model.CouponOrderLog{}
  208. )
  209. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  210. a, err := d.AddOrderLog(c, tx, o)
  211. if err == nil {
  212. if err = tx.Commit(); err != nil {
  213. tx.Rollback()
  214. }
  215. } else {
  216. tx.Rollback()
  217. }
  218. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  219. convCtx.So(err, convey.ShouldBeNil)
  220. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  221. })
  222. })
  223. })
  224. }
  225. func TestDaoConsumeCouponLog(t *testing.T) {
  226. convey.Convey("ConsumeCouponLog", t, func(convCtx convey.C) {
  227. var (
  228. c = context.Background()
  229. mid = int64(0)
  230. orderNo = ""
  231. ct = int8(0)
  232. )
  233. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  234. rs, err := d.ConsumeCouponLog(c, mid, orderNo, ct)
  235. convCtx.Convey("Then err should be nil.rs should not be nil.", func(convCtx convey.C) {
  236. convCtx.So(err, convey.ShouldBeNil)
  237. convCtx.So(rs, convey.ShouldNotBeNil)
  238. })
  239. })
  240. })
  241. }
  242. func TestDaoByMidAndBatchToken(t *testing.T) {
  243. convey.Convey("ByMidAndBatchToken", t, func(convCtx convey.C) {
  244. var (
  245. c = context.Background()
  246. mid = int64(0)
  247. batchToken = ""
  248. )
  249. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  250. r, err := d.ByMidAndBatchToken(c, mid, batchToken)
  251. convCtx.Convey("Then err should be nil.r should be nil.", func(convCtx convey.C) {
  252. convCtx.So(err, convey.ShouldBeNil)
  253. convCtx.So(r, convey.ShouldBeNil)
  254. })
  255. })
  256. })
  257. }
  258. func TestDaoUpdateBlance(t *testing.T) {
  259. convey.Convey("UpdateBlance", t, func(convCtx convey.C) {
  260. var (
  261. c = context.Background()
  262. tx, _ = d.BeginTran(context.Background())
  263. id = int64(0)
  264. mid = int64(0)
  265. ver = int64(0)
  266. balance = int64(0)
  267. )
  268. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  269. a, err := d.UpdateBlance(c, tx, id, mid, ver, balance)
  270. if err == nil {
  271. if err = tx.Commit(); err != nil {
  272. tx.Rollback()
  273. }
  274. } else {
  275. tx.Rollback()
  276. }
  277. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  278. convCtx.So(err, convey.ShouldBeNil)
  279. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  280. })
  281. })
  282. })
  283. }
  284. func TestDaoOrderInPay(t *testing.T) {
  285. convey.Convey("OrderInPay", t, func(convCtx convey.C) {
  286. var (
  287. c = context.Background()
  288. state = int8(0)
  289. no = time.Now()
  290. )
  291. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  292. res, err := d.OrderInPay(c, state, no)
  293. convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
  294. convCtx.So(err, convey.ShouldBeNil)
  295. convCtx.So(res, convey.ShouldBeNil)
  296. })
  297. })
  298. })
  299. }
  300. func TestDaoBatchUpdateBlance(t *testing.T) {
  301. convey.Convey("BatchUpdateBlance", t, func(convCtx convey.C) {
  302. var (
  303. c = context.Background()
  304. tx, _ = d.BeginTran(context.Background())
  305. mid = int64(0)
  306. blances = []*model.CouponBalanceInfo{}
  307. blance = &model.CouponBalanceInfo{}
  308. )
  309. blances = append(blances, blance)
  310. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  311. a, err := d.BatchUpdateBlance(c, tx, mid, blances)
  312. if err == nil {
  313. if err = tx.Commit(); err != nil {
  314. tx.Rollback()
  315. }
  316. } else {
  317. tx.Rollback()
  318. }
  319. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  320. convCtx.So(err, convey.ShouldBeNil)
  321. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  322. })
  323. })
  324. })
  325. }
  326. func TestDaoBatchInsertBlanceLog(t *testing.T) {
  327. convey.Convey("BatchInsertBlanceLog", t, func(convCtx convey.C) {
  328. var (
  329. c = context.Background()
  330. tx, _ = d.BeginTran(context.Background())
  331. mid = int64(0)
  332. ls = []*model.CouponBalanceChangeLog{}
  333. l = &model.CouponBalanceChangeLog{}
  334. )
  335. ls = append(ls, l)
  336. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  337. a, err := d.BatchInsertBlanceLog(c, tx, mid, ls)
  338. if err == nil {
  339. if err = tx.Commit(); err != nil {
  340. tx.Rollback()
  341. }
  342. } else {
  343. tx.Rollback()
  344. }
  345. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  346. convCtx.So(err, convey.ShouldBeNil)
  347. convCtx.So(a, convey.ShouldBeGreaterThanOrEqualTo, 0)
  348. })
  349. })
  350. })
  351. }
  352. func TestDaoBlanceList(t *testing.T) {
  353. convey.Convey("BlanceList", t, func(convCtx convey.C) {
  354. var (
  355. c = context.Background()
  356. mid = int64(0)
  357. ct = int8(0)
  358. )
  359. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  360. res, err := d.BlanceList(c, mid, ct)
  361. convCtx.Convey("Then err should be nil.res should be nil.", func(convCtx convey.C) {
  362. convCtx.So(err, convey.ShouldBeNil)
  363. convCtx.So(res, convey.ShouldBeNil)
  364. })
  365. })
  366. })
  367. }
  368. func TestDaoUpdateUserCard(t *testing.T) {
  369. convey.Convey("UpdateUserCard", t, func(convCtx convey.C) {
  370. var (
  371. c = context.Background()
  372. mid = int64(0)
  373. state = int8(0)
  374. couponToken = ""
  375. batchToken = ""
  376. )
  377. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  378. a, err := d.UpdateUserCard(c, mid, state, couponToken, batchToken)
  379. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  380. convCtx.So(err, convey.ShouldBeNil)
  381. convCtx.So(a, convey.ShouldNotBeNil)
  382. })
  383. })
  384. })
  385. }
  386. func TestDaoClose(t *testing.T) {
  387. convey.Convey("TestDaoClose", t, func(convCtx convey.C) {
  388. d.Close()
  389. })
  390. }