income_test.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoGetAvTagRatio(t *testing.T) {
  9. convey.Convey("GetAvTagRatio", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. from = int64(0)
  13. limit = int64(10)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. Exec(c, "INSERT INTO av_charge_ratio(tag_id,av_id) VALUES(1,2) ON DUPLICATE KEY UPDATE tag_id=VALUES(tag_id), av_id=VALUES(av_id)")
  17. infos, err := d.GetAvTagRatio(c, from, limit)
  18. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(infos, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoGetAvIncomeInfo(t *testing.T) {
  26. convey.Convey("GetAvIncomeInfo", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. avID = int64(1)
  30. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. Exec(c, "INSERT INTO av_income(av_id,mid,income,date) VALUES(1,2,3,'2018-06-24') ON DUPLICATE KEY UPDATE income=VALUES(income), av_id=VALUES(av_id)")
  34. info, err := d.GetAvIncomeInfo(c, avID, date)
  35. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(info, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestDaoTxInsertTagIncome(t *testing.T) {
  43. convey.Convey("TxInsertTagIncome", t, func(ctx convey.C) {
  44. var (
  45. c = context.Background()
  46. tx, _ = d.BeginTran(c)
  47. sql = "(1, 2, 3, 4, 5, '2018-06-23')"
  48. )
  49. defer tx.Commit()
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. rows, err := d.TxInsertTagIncome(tx, sql)
  52. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(rows, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoGetTagAvTotalIncome(t *testing.T) {
  60. convey.Convey("GetTagAvTotalIncome", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. tagID = int64(2)
  64. avID = int64(1)
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. Exec(c, "INSERT INTO up_tag_income (tag_id, av_id, total_income, date) VALUES(2, 1, 100,'2018-06-24') ON DUPLICATE KEY UPDATE tag_id=VALUES(tag_id),av_id=VALUES(av_id)")
  68. infos, err := d.GetTagAvTotalIncome(c, tagID, avID)
  69. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(infos, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoListAvIncome(t *testing.T) {
  77. convey.Convey("ListAvIncome", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. id = int64(0)
  81. limit = int(100)
  82. )
  83. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  84. avIncome, err := d.ListAvIncome(c, id, limit)
  85. ctx.Convey("Then err should be nil.avIncome should not be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. ctx.So(avIncome, convey.ShouldNotBeNil)
  88. })
  89. })
  90. })
  91. }
  92. func TestDaoListUpAccount(t *testing.T) {
  93. convey.Convey("ListUpAccount", t, func(ctx convey.C) {
  94. var (
  95. c = context.Background()
  96. withdrawDate = "2018-06"
  97. ctime = "2018-06-23"
  98. from = int(0)
  99. limit = int(100)
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. upAct, err := d.ListUpAccount(c, withdrawDate, ctime, from, limit)
  103. ctx.Convey("Then err should be nil.upAct should not be nil.", func(ctx convey.C) {
  104. ctx.So(err, convey.ShouldBeNil)
  105. ctx.So(upAct, convey.ShouldNotBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestDaoListUpIncome(t *testing.T) {
  111. convey.Convey("ListUpIncome", t, func(ctx convey.C) {
  112. var (
  113. c = context.Background()
  114. table = "up_income"
  115. date = "2018-06-23"
  116. id = int64(0)
  117. limit = int(100)
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. um, err := d.ListUpIncome(c, table, date, id, limit)
  121. ctx.Convey("Then err should be nil.um should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. ctx.So(um, convey.ShouldNotBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestDaoListUpWithdraw(t *testing.T) {
  129. convey.Convey("ListUpWithdraw", t, func(ctx convey.C) {
  130. var (
  131. c = context.Background()
  132. date = "2018-06-23"
  133. from = int(0)
  134. limit = int(100)
  135. )
  136. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  137. ups, err := d.ListUpWithdraw(c, date, from, limit)
  138. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  139. ctx.So(err, convey.ShouldBeNil)
  140. ctx.So(ups, convey.ShouldNotBeNil)
  141. })
  142. })
  143. })
  144. }
  145. func TestDaoGetUpTotalIncome(t *testing.T) {
  146. convey.Convey("GetUpTotalIncome", t, func(ctx convey.C) {
  147. var (
  148. c = context.Background()
  149. from = int64(0)
  150. limit = int64(100)
  151. )
  152. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  153. infos, err := d.GetUpTotalIncome(c, from, limit)
  154. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  155. ctx.So(err, convey.ShouldBeNil)
  156. ctx.So(infos, convey.ShouldNotBeNil)
  157. })
  158. })
  159. })
  160. }
  161. func TestDaoGetUpIncome(t *testing.T) {
  162. convey.Convey("GetUpIncome", t, func(ctx convey.C) {
  163. var (
  164. c = context.Background()
  165. date = time.Now()
  166. from = int64(0)
  167. limit = int64(100)
  168. )
  169. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  170. infos, err := d.GetUpIncome(c, date, from, limit)
  171. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  172. ctx.So(err, convey.ShouldBeNil)
  173. ctx.So(infos, convey.ShouldNotBeNil)
  174. })
  175. })
  176. })
  177. }
  178. func TestDaoGetAvIncome(t *testing.T) {
  179. convey.Convey("GetAvIncome", t, func(ctx convey.C) {
  180. var (
  181. c = context.Background()
  182. date = time.Now()
  183. id = int64(0)
  184. limit = int64(10)
  185. )
  186. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  187. infos, err := d.GetAvIncome(c, date, id, limit)
  188. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  189. ctx.So(err, convey.ShouldBeNil)
  190. ctx.So(infos, convey.ShouldNotBeNil)
  191. })
  192. })
  193. })
  194. }
  195. func TestDaoGetUpTotalIncomeCnt(t *testing.T) {
  196. convey.Convey("GetUpTotalIncomeCnt", t, func(ctx convey.C) {
  197. var (
  198. c = context.Background()
  199. )
  200. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  201. upCnt, err := d.GetUpTotalIncomeCnt(c)
  202. ctx.Convey("Then err should be nil.upCnt should not be nil.", func(ctx convey.C) {
  203. ctx.So(err, convey.ShouldBeNil)
  204. ctx.So(upCnt, convey.ShouldNotBeNil)
  205. })
  206. })
  207. })
  208. }
  209. func TestDaoGetAvStatisCount(t *testing.T) {
  210. convey.Convey("GetAvStatisCount", t, func(ctx convey.C) {
  211. var (
  212. c = context.Background()
  213. )
  214. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  215. cnt, err := d.GetAvStatisCount(c)
  216. ctx.Convey("Then err should be nil.cnt should not be nil.", func(ctx convey.C) {
  217. ctx.So(err, convey.ShouldBeNil)
  218. ctx.So(cnt, convey.ShouldNotBeNil)
  219. })
  220. })
  221. })
  222. }