mysql_test.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaomidHit(t *testing.T) {
  9. var (
  10. mid = int64(0)
  11. )
  12. convey.Convey("midHit", t, func(ctx convey.C) {
  13. p1 := d.midHit(mid)
  14. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestDaoaidHit(t *testing.T) {
  20. var (
  21. aid = int64(0)
  22. )
  23. convey.Convey("aidHit", t, func(ctx convey.C) {
  24. p1 := d.aidHit(aid)
  25. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  26. ctx.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDaohitCoinPeriod(t *testing.T) {
  31. var (
  32. c = context.TODO()
  33. now, _ = time.Parse("2006-01-02 15:04:05", "2018-01-26 00:00:00")
  34. )
  35. convey.Convey("hitCoinPeriod", t, func(ctx convey.C) {
  36. id, err := d.hitCoinPeriod(c, now)
  37. ctx.Convey("Error should be nil", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. })
  40. ctx.Convey("id should not be nil", func(ctx convey.C) {
  41. ctx.So(id, convey.ShouldNotBeNil)
  42. })
  43. })
  44. }
  45. func TestDaoUpdateCoinSettleBD(t *testing.T) {
  46. var (
  47. c = context.TODO()
  48. aid = int64(4051951)
  49. tp = int64(1)
  50. expSub = int64(20)
  51. describe = "UpdateCoinSettleBD"
  52. now = time.Now()
  53. )
  54. convey.Convey("UpdateCoinSettleBD", t, func(ctx convey.C) {
  55. currentYear, currentMonth, _ := now.Date()
  56. curTime := now.Location()
  57. firstDay := time.Date(currentYear, currentMonth, 1, 0, 0, 0, 0, curTime)
  58. now = firstDay.AddDate(0, 1, -1)
  59. affect, err := d.UpdateCoinSettleBD(c, aid, tp, expSub, describe, now)
  60. ctx.Convey("Error should be nil", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. ctx.Convey("affect should not be nil", func(ctx convey.C) {
  64. ctx.So(affect, convey.ShouldNotBeNil)
  65. })
  66. })
  67. }
  68. func TestDaoCoinList(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. mid = int64(4051951)
  72. tp = int64(1)
  73. ts = int64(time.Now().Unix())
  74. size = int64(1024)
  75. )
  76. convey.Convey("CoinList", t, func(ctx convey.C) {
  77. _, err := d.CoinList(c, mid, tp, ts, size)
  78. ctx.Convey("Error should be nil", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. })
  81. // ctx.Convey("rcs should not be nil", func(ctx convey.C) {
  82. // ctx.So(rcs, convey.ShouldNotBeEmpty)
  83. // })
  84. })
  85. }
  86. func TestDaoCoinsAddedByMid(t *testing.T) {
  87. var (
  88. c = context.TODO()
  89. mid = int64(4051951)
  90. aid = int64(12)
  91. tp = int64(20)
  92. )
  93. convey.Convey("CoinsAddedByMid", t, func(ctx convey.C) {
  94. added, err := d.CoinsAddedByMid(c, mid, aid, tp)
  95. ctx.Convey("Error should be nil", func(ctx convey.C) {
  96. ctx.So(err, convey.ShouldBeNil)
  97. })
  98. ctx.Convey("added should not be nil", func(ctx convey.C) {
  99. ctx.So(added, convey.ShouldNotBeNil)
  100. })
  101. })
  102. }
  103. func TestDaoAddedCoins(t *testing.T) {
  104. var (
  105. c = context.TODO()
  106. mid = int64(4051951)
  107. upMid = int64(4051950)
  108. )
  109. convey.Convey("AddedCoins", t, func(ctx convey.C) {
  110. added, err := d.AddedCoins(c, mid, upMid)
  111. ctx.Convey("Error should be nil", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. })
  114. ctx.Convey("added should not be nil", func(ctx convey.C) {
  115. ctx.So(added, convey.ShouldNotBeNil)
  116. })
  117. })
  118. }
  119. func TestDaoUserCoinsAdded(t *testing.T) {
  120. var (
  121. c = context.TODO()
  122. mid = int64(1)
  123. )
  124. convey.Convey("UserCoinsAdded", t, func(ctx convey.C) {
  125. addeds, err := d.UserCoinsAdded(c, mid)
  126. ctx.Convey("Error should be nil", func(ctx convey.C) {
  127. ctx.So(err, convey.ShouldBeNil)
  128. })
  129. ctx.Convey("addeds should not be nil", func(ctx convey.C) {
  130. ctx.So(addeds, convey.ShouldNotBeNil)
  131. })
  132. })
  133. }
  134. func TestDaoInsertCoinArchive(t *testing.T) {
  135. var (
  136. c = context.TODO()
  137. aid = int64(1)
  138. tp = int64(21)
  139. mid = int64(4051951)
  140. timestamp = int64(time.Now().Unix())
  141. multiply = int64(0)
  142. )
  143. convey.Convey("InsertCoinArchive", t, func(ctx convey.C) {
  144. err := d.InsertCoinArchive(c, aid, tp, mid, timestamp, multiply)
  145. ctx.Convey("Error should be nil", func(ctx convey.C) {
  146. ctx.So(err, convey.ShouldBeNil)
  147. })
  148. })
  149. }
  150. func TestDaoInsertCoinMember(t *testing.T) {
  151. var (
  152. c = context.TODO()
  153. aid = int64(1)
  154. tp = int64(2)
  155. mid = int64(4051951)
  156. timestamp = int64(time.Now().Unix())
  157. multiply = int64(21)
  158. upMid = int64(1)
  159. )
  160. convey.Convey("InsertCoinMember", t, func(ctx convey.C) {
  161. err := d.InsertCoinMember(c, aid, tp, mid, timestamp, multiply, upMid)
  162. ctx.Convey("Error should be nil", func(ctx convey.C) {
  163. ctx.So(err, convey.ShouldBeNil)
  164. })
  165. })
  166. }
  167. func TestDaoUpdateItemCoinCount(t *testing.T) {
  168. var (
  169. c = context.TODO()
  170. aid = int64(0)
  171. tp = int64(0)
  172. count = int64(0)
  173. )
  174. convey.Convey("UpdateItemCoinCount", t, func(ctx convey.C) {
  175. err := d.UpdateItemCoinCount(c, aid, tp, count)
  176. ctx.Convey("Error should be nil", func(ctx convey.C) {
  177. ctx.So(err, convey.ShouldBeNil)
  178. })
  179. })
  180. }
  181. func TestDaoRawItemCoin(t *testing.T) {
  182. var (
  183. c = context.TODO()
  184. aid = int64(0)
  185. tp = int64(0)
  186. )
  187. convey.Convey("RawItemCoin", t, func(ctx convey.C) {
  188. count, err := d.RawItemCoin(c, aid, tp)
  189. ctx.Convey("Error should be nil", func(ctx convey.C) {
  190. ctx.So(err, convey.ShouldBeNil)
  191. })
  192. ctx.Convey("count should not be nil", func(ctx convey.C) {
  193. ctx.So(count, convey.ShouldNotBeNil)
  194. })
  195. })
  196. }
  197. func TestDaoUpdateCoinMemberCount(t *testing.T) {
  198. var (
  199. c = context.TODO()
  200. mid = int64(4051951)
  201. upMid = int64(1)
  202. count = int64(2)
  203. )
  204. convey.Convey("UpdateCoinMemberCount", t, func(ctx convey.C) {
  205. err := d.UpdateCoinMemberCount(c, mid, upMid, count)
  206. ctx.Convey("Error should be nil", func(ctx convey.C) {
  207. ctx.So(err, convey.ShouldBeNil)
  208. })
  209. })
  210. }
  211. func TestDaoBeginTran(t *testing.T) {
  212. var (
  213. c = context.TODO()
  214. )
  215. convey.Convey("BeginTran", t, func(ctx convey.C) {
  216. no, err := d.BeginTran(c)
  217. ctx.Convey("Error should be nil", func(ctx convey.C) {
  218. ctx.So(err, convey.ShouldBeNil)
  219. })
  220. ctx.Convey("no should not be nil", func(ctx convey.C) {
  221. ctx.So(no, convey.ShouldNotBeNil)
  222. })
  223. })
  224. }
  225. func TestDaoUpdateItemCoins(t *testing.T) {
  226. var (
  227. c = context.TODO()
  228. aid = int64(1)
  229. tp = int64(20)
  230. coins = int64(20)
  231. now = time.Now()
  232. )
  233. convey.Convey("UpdateItemCoins", t, func(ctx convey.C) {
  234. affect, err := d.UpdateItemCoins(c, aid, tp, coins, now)
  235. ctx.Convey("Error should be nil", func(ctx convey.C) {
  236. ctx.So(err, convey.ShouldBeNil)
  237. })
  238. ctx.Convey("affect should not be nil", func(ctx convey.C) {
  239. ctx.So(affect, convey.ShouldNotBeNil)
  240. })
  241. })
  242. }