data_test.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoInsertBGMIncomeStatis(t *testing.T) {
  8. convey.Convey("InsertBGMIncomeStatis", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. sid = int64(100)
  12. income = int64(1090)
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. Exec(c, "DELETE FROM bgm_income_statis WHERE sid=100")
  16. rows, err := d.InsertBGMIncomeStatis(c, sid, income)
  17. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(rows, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoGetBGMIncome(t *testing.T) {
  25. convey.Convey("GetBGMIncome", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. statis, err := d.GetBGMIncome(c)
  31. ctx.Convey("Then err should be nil.statis should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(statis, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoGetCreditScore(t *testing.T) {
  39. convey.Convey("GetCreditScore", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. table = "video"
  43. id = int64(100)
  44. limit = int64(200)
  45. )
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. scores, last, err := d.GetCreditScore(c, table, id, limit)
  48. ctx.Convey("Then err should be nil.scores,last should not be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(last, convey.ShouldNotBeNil)
  51. ctx.So(scores, convey.ShouldNotBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestDaoSyncCreditScore(t *testing.T) {
  57. convey.Convey("SyncCreditScore", t, func(ctx convey.C) {
  58. var (
  59. c = context.Background()
  60. values = "(100, 100)"
  61. )
  62. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  63. rows, err := d.SyncCreditScore(c, values)
  64. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(rows, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }
  71. func TestDaoGetAvBaseIncome(t *testing.T) {
  72. convey.Convey("GetAvBaseIncome", t, func(ctx convey.C) {
  73. var (
  74. c = context.Background()
  75. table = "up_income"
  76. id = int64(0)
  77. limit = int64(10)
  78. )
  79. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  80. d.db.Exec(c, "INSERT INTO up_income(mid,date,income) VALUES(1,'2018-06-24',2) ON DUPLICATE KEY UPDATE income=VALUES(income)")
  81. abs, last, err := d.GetAvBaseIncome(c, table, id, limit)
  82. ctx.Convey("Then err should be nil.abs,last should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(last, convey.ShouldNotBeNil)
  85. ctx.So(abs, convey.ShouldNotBeNil)
  86. })
  87. })
  88. })
  89. }
  90. func TestDaoBatchUpdateUpIncome(t *testing.T) {
  91. convey.Convey("BatchUpdateUpIncome", t, func(ctx convey.C) {
  92. var (
  93. c = context.Background()
  94. table = "up_income"
  95. values = "(100, '2018-06-23', 100)"
  96. )
  97. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  98. rows, err := d.BatchUpdateUpIncome(c, table, values)
  99. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  100. ctx.So(err, convey.ShouldBeNil)
  101. ctx.So(rows, convey.ShouldNotBeNil)
  102. })
  103. })
  104. })
  105. }
  106. func TestDaoGetAvs(t *testing.T) {
  107. convey.Convey("GetAvs", t, func(ctx convey.C) {
  108. var (
  109. c = context.Background()
  110. date = "2018-06-23"
  111. mid = int64(100)
  112. )
  113. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  114. avs, err := d.GetAvs(c, date, mid)
  115. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  116. ctx.So(err, convey.ShouldBeNil)
  117. ctx.So(avs, convey.ShouldNotBeNil)
  118. })
  119. })
  120. })
  121. }
  122. func TestDaoGetAvCharges(t *testing.T) {
  123. convey.Convey("GetAvCharges", t, func(ctx convey.C) {
  124. var (
  125. c = context.Background()
  126. avIds = []int64{100, 200}
  127. date = "2018-06-23"
  128. )
  129. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  130. charges, err := d.GetAvCharges(c, avIds, date)
  131. ctx.Convey("Then err should be nil.charges should not be nil.", func(ctx convey.C) {
  132. ctx.So(err, convey.ShouldBeNil)
  133. ctx.So(charges, convey.ShouldNotBeNil)
  134. })
  135. })
  136. })
  137. }
  138. func TestDaoGetUpChargeRatio(t *testing.T) {
  139. convey.Convey("GetUpChargeRatio", t, func(ctx convey.C) {
  140. var (
  141. c = context.Background()
  142. tagID = int64(10)
  143. )
  144. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  145. ups, err := d.GetUpChargeRatio(c, tagID)
  146. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  147. ctx.So(err, convey.ShouldBeNil)
  148. ctx.So(ups, convey.ShouldNotBeNil)
  149. })
  150. })
  151. })
  152. }
  153. func TestDaoGetUpIncomeStatis(t *testing.T) {
  154. convey.Convey("GetUpIncomeStatis", t, func(ctx convey.C) {
  155. var (
  156. c = context.Background()
  157. mids = []int64{100, 200}
  158. )
  159. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  160. ups, err := d.GetUpIncomeStatis(c, mids)
  161. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  162. ctx.So(err, convey.ShouldBeNil)
  163. ctx.So(ups, convey.ShouldNotBeNil)
  164. })
  165. })
  166. })
  167. }
  168. func TestDaoGetUpIncomeDate(t *testing.T) {
  169. convey.Convey("GetUpIncomeDate", t, func(ctx convey.C) {
  170. var (
  171. c = context.Background()
  172. mids = []int64{100, 200}
  173. table = "up_income"
  174. date = "2018-06-23"
  175. )
  176. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  177. ups, err := d.GetUpIncomeDate(c, mids, table, date)
  178. ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
  179. ctx.So(err, convey.ShouldBeNil)
  180. ctx.So(ups, convey.ShouldNotBeNil)
  181. })
  182. })
  183. })
  184. }
  185. func TestDaoUpdateDate(t *testing.T) {
  186. convey.Convey("UpdateDate", t, func(ctx convey.C) {
  187. var (
  188. tx, _ = d.BeginTran(context.Background())
  189. stmt = "UPDATE up_info_video SET account_state=1 WHERE mid=10"
  190. )
  191. defer tx.Commit()
  192. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  193. count, err := d.UpdateDate(tx, stmt)
  194. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  195. ctx.So(err, convey.ShouldBeNil)
  196. ctx.So(count, convey.ShouldNotBeNil)
  197. })
  198. })
  199. })
  200. }