mysql_test.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. package dao
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "math/rand"
  7. "time"
  8. // xsql"database/sql"
  9. "go-common/app/admin/main/coupon/model"
  10. "testing"
  11. "github.com/smartystreets/goconvey/convey"
  12. )
  13. func TestDaoBeginTran(t *testing.T) {
  14. convey.Convey("BeginTran", t, func(convCtx convey.C) {
  15. var (
  16. c = context.Background()
  17. )
  18. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  19. p1, err := d.BeginTran(c)
  20. convCtx.Convey("Then err should be nil.p1 should not be nil.", func(convCtx convey.C) {
  21. convCtx.So(err, convey.ShouldBeNil)
  22. convCtx.So(p1, convey.ShouldNotBeNil)
  23. })
  24. })
  25. })
  26. }
  27. func TestDaohitAllowanceInfo(t *testing.T) {
  28. convey.Convey("hitAllowanceInfo", t, func(convCtx convey.C) {
  29. var (
  30. mid = int64(1)
  31. )
  32. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  33. p1 := hitAllowanceInfo(mid)
  34. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  35. convCtx.So(p1, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaohitAllowanceChangeLog(t *testing.T) {
  41. convey.Convey("hitAllowanceChangeLog", t, func(convCtx convey.C) {
  42. var (
  43. mid = int64(0)
  44. )
  45. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  46. p1 := hitAllowanceChangeLog(mid)
  47. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  48. convCtx.So(p1, convey.ShouldNotBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaohitViewInfo(t *testing.T) {
  54. convey.Convey("hitViewInfo", t, func(convCtx convey.C) {
  55. var (
  56. mid = int64(0)
  57. )
  58. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  59. p1 := hitViewInfo(mid)
  60. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  61. convCtx.So(p1, convey.ShouldNotBeNil)
  62. })
  63. })
  64. })
  65. }
  66. // go test -test.v -test.run TestBatchList
  67. func TestDaoBatchList(t *testing.T) {
  68. convey.Convey("BatchList", t, func(convCtx convey.C) {
  69. var (
  70. c = context.Background()
  71. appid = int64(1)
  72. t = int8(0)
  73. )
  74. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  75. res, err := d.BatchList(c, appid, t)
  76. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  77. convCtx.So(err, convey.ShouldBeNil)
  78. convCtx.So(res, convey.ShouldNotBeNil)
  79. })
  80. })
  81. })
  82. }
  83. func TestDaoBatchViewList(t *testing.T) {
  84. convey.Convey("BatchViewList", t, func(convCtx convey.C) {
  85. var (
  86. c = context.Background()
  87. appid = int64(0)
  88. batchToken = ""
  89. no = int8(0)
  90. )
  91. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  92. res, err := d.BatchViewList(c, appid, batchToken, no)
  93. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  94. convCtx.So(err, convey.ShouldBeNil)
  95. convCtx.So(res, convey.ShouldNotBeNil)
  96. })
  97. })
  98. })
  99. }
  100. func TestDaoAddBatchInfo(t *testing.T) {
  101. convey.Convey("AddBatchInfo", t, func(convCtx convey.C) {
  102. var (
  103. c = context.Background()
  104. bi = &model.CouponBatchInfo{}
  105. b bytes.Buffer
  106. )
  107. b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
  108. b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
  109. b.WriteString(time.Now().Format("20060102150405"))
  110. bi.BatchToken = b.String()
  111. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  112. a, err := d.AddBatchInfo(c, bi)
  113. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  114. convCtx.So(err, convey.ShouldBeNil)
  115. convCtx.So(a, convey.ShouldNotBeNil)
  116. })
  117. })
  118. })
  119. }
  120. func TestDaoAllAppInfo(t *testing.T) {
  121. convey.Convey("AllAppInfo", t, func(convCtx convey.C) {
  122. var (
  123. c = context.Background()
  124. )
  125. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  126. res, err := d.AllAppInfo(c)
  127. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  128. convCtx.So(err, convey.ShouldBeNil)
  129. convCtx.So(res, convey.ShouldNotBeNil)
  130. })
  131. })
  132. })
  133. }
  134. func TestDaoAddAllowanceBatchInfo(t *testing.T) {
  135. convey.Convey("AddAllowanceBatchInfo", t, func(convCtx convey.C) {
  136. var (
  137. c = context.Background()
  138. b bytes.Buffer
  139. bi = &model.CouponBatchInfo{}
  140. )
  141. b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
  142. b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
  143. b.WriteString(time.Now().Format("20060102150405"))
  144. bi.BatchToken = b.String()
  145. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  146. a, err := d.AddAllowanceBatchInfo(c, bi)
  147. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  148. convCtx.So(err, convey.ShouldBeNil)
  149. convCtx.So(a, convey.ShouldNotBeNil)
  150. })
  151. })
  152. })
  153. }
  154. func TestDaoUpdateAllowanceBatchInfo(t *testing.T) {
  155. convey.Convey("UpdateAllowanceBatchInfo", t, func(convCtx convey.C) {
  156. var (
  157. c = context.Background()
  158. b = &model.CouponBatchInfo{}
  159. )
  160. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  161. a, err := d.UpdateAllowanceBatchInfo(c, b)
  162. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  163. convCtx.So(err, convey.ShouldBeNil)
  164. convCtx.So(a, convey.ShouldNotBeNil)
  165. })
  166. })
  167. })
  168. }
  169. func TestDaoUpdateBatchStatus(t *testing.T) {
  170. convey.Convey("UpdateBatchStatus", t, func(convCtx convey.C) {
  171. var (
  172. c = context.Background()
  173. status = int8(0)
  174. operator = ""
  175. id = int64(0)
  176. )
  177. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  178. a, err := d.UpdateBatchStatus(c, status, operator, id)
  179. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  180. convCtx.So(err, convey.ShouldBeNil)
  181. convCtx.So(a, convey.ShouldNotBeNil)
  182. })
  183. })
  184. })
  185. }
  186. func TestDaoBatchInfo(t *testing.T) {
  187. convey.Convey("BatchInfo", t, func(convCtx convey.C) {
  188. var (
  189. c = context.Background()
  190. token = ""
  191. )
  192. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  193. r, err := d.BatchInfo(c, token)
  194. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  195. convCtx.So(err, convey.ShouldBeNil)
  196. convCtx.So(r, convey.ShouldNotBeNil)
  197. })
  198. })
  199. })
  200. }
  201. func TestDaoUpdateAllowanceStatus(t *testing.T) {
  202. convey.Convey("UpdateAllowanceStatus", t, func(convCtx convey.C) {
  203. var (
  204. c = context.Background()
  205. tx, _ = d.BeginTran(context.Background())
  206. state = int8(0)
  207. mid = int64(0)
  208. token = ""
  209. ver = int64(0)
  210. )
  211. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  212. a, err := d.UpdateAllowanceStatus(c, tx, state, mid, token, ver)
  213. if err == nil {
  214. if err = tx.Commit(); err != nil {
  215. tx.Rollback()
  216. }
  217. } else {
  218. tx.Rollback()
  219. }
  220. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  221. convCtx.So(err, convey.ShouldBeNil)
  222. convCtx.So(a, convey.ShouldNotBeNil)
  223. })
  224. })
  225. })
  226. }
  227. func TestDaoAllowanceByToken(t *testing.T) {
  228. convey.Convey("AllowanceByToken", t, func(convCtx convey.C) {
  229. var (
  230. c = context.Background()
  231. mid = int64(13)
  232. token = "000000119720180929180009"
  233. )
  234. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  235. r, err := d.AllowanceByToken(c, mid, token)
  236. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  237. convCtx.So(err, convey.ShouldBeNil)
  238. convCtx.So(r, convey.ShouldNotBeNil)
  239. })
  240. })
  241. })
  242. }
  243. func TestDaoInsertCouponAllowanceHistory(t *testing.T) {
  244. convey.Convey("InsertCouponAllowanceHistory", t, func(convCtx convey.C) {
  245. var (
  246. c = context.Background()
  247. tx, _ = d.BeginTran(context.Background())
  248. l = &model.CouponAllowanceChangeLog{}
  249. )
  250. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  251. a, err := d.InsertCouponAllowanceHistory(c, tx, l)
  252. if err == nil {
  253. if err = tx.Commit(); err != nil {
  254. tx.Rollback()
  255. }
  256. } else {
  257. tx.Rollback()
  258. }
  259. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  260. convCtx.So(err, convey.ShouldBeNil)
  261. convCtx.So(a, convey.ShouldNotBeNil)
  262. })
  263. })
  264. })
  265. }
  266. func TestDaoAllowanceList(t *testing.T) {
  267. convey.Convey("AllowanceList", t, func(convCtx convey.C) {
  268. var (
  269. c = context.Background()
  270. arg = &model.ArgAllowanceSearch{Mid: 3}
  271. )
  272. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  273. res, err := d.AllowanceList(c, arg)
  274. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  275. convCtx.So(err, convey.ShouldBeNil)
  276. convCtx.So(res, convey.ShouldNotBeNil)
  277. })
  278. })
  279. })
  280. }
  281. func TestDaoAddViewBatch(t *testing.T) {
  282. convey.Convey("AddViewBatch", t, func(convCtx convey.C) {
  283. var (
  284. c = context.Background()
  285. arg = &model.ArgCouponViewBatch{}
  286. b bytes.Buffer
  287. )
  288. b.WriteString(fmt.Sprintf("%07d", rand.Int63n(9999999)))
  289. b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
  290. b.WriteString(time.Now().Format("20060102150405"))
  291. arg.BatchToken = b.String()
  292. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  293. err := d.AddViewBatch(c, arg)
  294. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  295. convCtx.So(err, convey.ShouldBeNil)
  296. })
  297. })
  298. })
  299. }
  300. func TestDaoUpdateViewBatch(t *testing.T) {
  301. convey.Convey("UpdateViewBatch", t, func(convCtx convey.C) {
  302. var (
  303. c = context.Background()
  304. arg = &model.ArgCouponViewBatch{}
  305. )
  306. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  307. err := d.UpdateViewBatch(c, arg)
  308. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  309. convCtx.So(err, convey.ShouldBeNil)
  310. })
  311. })
  312. })
  313. }
  314. func TestDaoTxUpdateViewInfo(t *testing.T) {
  315. convey.Convey("TxUpdateViewInfo", t, func(convCtx convey.C) {
  316. var (
  317. tx, _ = d.BeginTran(context.Background())
  318. status = int8(0)
  319. couponToken = ""
  320. mid = int64(0)
  321. )
  322. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  323. err := d.TxUpdateViewInfo(tx, status, couponToken, mid)
  324. if err == nil {
  325. if err = tx.Commit(); err != nil {
  326. tx.Rollback()
  327. }
  328. } else {
  329. tx.Rollback()
  330. }
  331. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  332. convCtx.So(err, convey.ShouldBeNil)
  333. })
  334. })
  335. })
  336. }
  337. func TestDaoTxCouponViewLog(t *testing.T) {
  338. convey.Convey("TxCouponViewLog", t, func(convCtx convey.C) {
  339. var (
  340. tx, _ = d.BeginTran(context.Background())
  341. arg = &model.CouponChangeLog{}
  342. )
  343. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  344. err := d.TxCouponViewLog(tx, arg)
  345. if err == nil {
  346. if err = tx.Commit(); err != nil {
  347. tx.Rollback()
  348. }
  349. } else {
  350. tx.Rollback()
  351. }
  352. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  353. convCtx.So(err, convey.ShouldBeNil)
  354. })
  355. })
  356. })
  357. }
  358. func TestDaoCouponViewInfo(t *testing.T) {
  359. convey.Convey("CouponViewInfo", t, func(convCtx convey.C) {
  360. var (
  361. c = context.Background()
  362. couponToken = ""
  363. mid = int64(0)
  364. )
  365. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  366. r, err := d.CouponViewInfo(c, couponToken, mid)
  367. convCtx.Convey("Then err should be nil.r should not be nil.", func(convCtx convey.C) {
  368. convCtx.So(err, convey.ShouldBeNil)
  369. convCtx.So(r, convey.ShouldNotBeNil)
  370. })
  371. })
  372. })
  373. }
  374. func TestDaoSearchViewCouponCount(t *testing.T) {
  375. convey.Convey("SearchViewCouponCount", t, func(convCtx convey.C) {
  376. var (
  377. c = context.Background()
  378. arg = &model.ArgSearchCouponView{}
  379. )
  380. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  381. count, err := d.SearchViewCouponCount(c, arg)
  382. convCtx.Convey("Then err should be nil.count should not be nil.", func(convCtx convey.C) {
  383. convCtx.So(err, convey.ShouldBeNil)
  384. convCtx.So(count, convey.ShouldNotBeNil)
  385. })
  386. })
  387. })
  388. }
  389. func TestDaoSearchViewCouponInfo(t *testing.T) {
  390. convey.Convey("SearchViewCouponInfo", t, func(convCtx convey.C) {
  391. var (
  392. c = context.Background()
  393. arg = &model.ArgSearchCouponView{}
  394. )
  395. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  396. res, err := d.SearchViewCouponInfo(c, arg)
  397. convCtx.Convey("Then err should be nil.res should not be nil.", func(convCtx convey.C) {
  398. convCtx.So(err, convey.ShouldBeNil)
  399. convCtx.So(res, convey.ShouldNotBeNil)
  400. })
  401. })
  402. })
  403. }
  404. func TestDaoBatchAddAllowanceCoupon(t *testing.T) {
  405. convey.Convey("BatchAddAllowanceCoupon", t, func(convCtx convey.C) {
  406. var (
  407. c = context.Background()
  408. b bytes.Buffer
  409. tx, _ = d.BeginTran(context.Background())
  410. cps = []*model.CouponAllowanceInfo{}
  411. )
  412. b.WriteString(fmt.Sprintf("%05d", 1))
  413. b.WriteString(fmt.Sprintf("%02d", rand.Int63n(99)))
  414. b.WriteString(fmt.Sprintf("%03d", time.Now().UnixNano()/1e6%1000))
  415. b.WriteString(time.Now().Format("20060102150405"))
  416. cp := &model.CouponAllowanceInfo{CouponToken: b.String()}
  417. cps = append(cps, cp)
  418. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  419. a, err := d.BatchAddAllowanceCoupon(c, tx, cps)
  420. if err == nil {
  421. if err = tx.Commit(); err != nil {
  422. tx.Rollback()
  423. }
  424. } else {
  425. tx.Rollback()
  426. }
  427. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  428. convCtx.So(err, convey.ShouldBeNil)
  429. convCtx.So(a, convey.ShouldNotBeNil)
  430. })
  431. })
  432. })
  433. }
  434. func TestDaoUpdateBatchInfo(t *testing.T) {
  435. convey.Convey("UpdateBatchInfo", t, func(convCtx convey.C) {
  436. var (
  437. c = context.Background()
  438. tx, _ = d.BeginTran(context.Background())
  439. token = ""
  440. count = int(0)
  441. )
  442. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  443. a, err := d.UpdateBatchInfo(c, tx, token, count)
  444. if err == nil {
  445. if err = tx.Commit(); err != nil {
  446. tx.Rollback()
  447. }
  448. } else {
  449. tx.Rollback()
  450. }
  451. convCtx.Convey("Then err should be nil.a should not be nil.", func(convCtx convey.C) {
  452. convCtx.So(err, convey.ShouldBeNil)
  453. convCtx.So(a, convey.ShouldNotBeNil)
  454. })
  455. })
  456. })
  457. }