mysql_test.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/service/main/point/model"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoBeginTran(t *testing.T) {
  11. convey.Convey("BeginTran", t, func(ctx convey.C) {
  12. var c = context.Background()
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1, err := d.BeginTran(c)
  15. ctx.Convey("Then err should be nil.p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. })
  21. }
  22. func TestDaoPointInfo(t *testing.T) {
  23. convey.Convey("PointInfo", t, func(ctx convey.C) {
  24. var (
  25. c = context.Background()
  26. mid = int64(1)
  27. )
  28. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  29. _, err := d.PointInfo(c, mid)
  30. ctx.Convey("Then err should be nil.pi should not be nil.", func(ctx convey.C) {
  31. ctx.So(err, convey.ShouldBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestDaoTxPointInfo(t *testing.T) {
  37. convey.Convey("TxPointInfo", t, func(ctx convey.C) {
  38. var (
  39. c = context.Background()
  40. mid = int64(1)
  41. )
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. tx, err := d.BeginTran(c)
  44. ctx.So(err, convey.ShouldBeNil)
  45. _, err = d.TxPointInfo(c, tx, mid)
  46. ctx.Convey("Then err should be nil.pi should not be nil.", func(ctx convey.C) {
  47. ctx.So(err, convey.ShouldBeNil)
  48. })
  49. })
  50. })
  51. }
  52. func TestDaoPointHistory(t *testing.T) {
  53. convey.Convey("PointHistory", t, func(ctx convey.C) {
  54. var (
  55. c = context.Background()
  56. mid = int64(1)
  57. cursor = int(1)
  58. ps = int(2)
  59. )
  60. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  61. _, err := d.PointHistory(c, mid, cursor, ps)
  62. ctx.Convey("Then err should be nil.phs should not be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. })
  65. })
  66. })
  67. }
  68. func TestDaoPointHistoryCount(t *testing.T) {
  69. convey.Convey("PointHistoryCount", t, func(ctx convey.C) {
  70. var (
  71. c = context.Background()
  72. mid = int64(1)
  73. )
  74. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  75. _, err := d.PointHistoryCount(c, mid)
  76. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. })
  81. }
  82. func TestDaoUpdatePointInfo(t *testing.T) {
  83. convey.Convey("UpdatePointInfo", t, func(ctx convey.C) {
  84. var (
  85. c = context.Background()
  86. pi = &model.PointInfo{}
  87. ver = int64(0)
  88. )
  89. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  90. tx, err := d.BeginTran(c)
  91. ctx.So(err, convey.ShouldBeNil)
  92. a, err := d.UpdatePointInfo(c, tx, pi, ver)
  93. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. ctx.So(a, convey.ShouldNotBeNil)
  96. })
  97. })
  98. })
  99. }
  100. func TestDaoInsertPoint(t *testing.T) {
  101. convey.Convey("InsertPoint", t, func(ctx convey.C) {
  102. var (
  103. c = context.Background()
  104. pi = &model.PointInfo{
  105. Mid: time.Now().Unix(),
  106. }
  107. )
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. tx, err := d.BeginTran(c)
  110. ctx.So(err, convey.ShouldBeNil)
  111. a, err := d.InsertPoint(c, tx, pi)
  112. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  113. ctx.So(err, convey.ShouldBeNil)
  114. ctx.So(a, convey.ShouldNotBeNil)
  115. })
  116. })
  117. })
  118. }
  119. func TestDaoInsertPointHistory(t *testing.T) {
  120. convey.Convey("InsertPointHistory", t, func(ctx convey.C) {
  121. var (
  122. c = context.Background()
  123. ph = &model.PointHistory{
  124. Mid: 1,
  125. ChangeTime: xtime.Time(time.Now().Unix()),
  126. }
  127. )
  128. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  129. tx, err := d.BeginTran(c)
  130. ctx.So(err, convey.ShouldBeNil)
  131. a, err := d.InsertPointHistory(c, tx, ph)
  132. ctx.Convey("Then err should be nil.a should not be nil.", func(ctx convey.C) {
  133. ctx.So(err, convey.ShouldBeNil)
  134. ctx.So(a, convey.ShouldNotBeNil)
  135. })
  136. })
  137. })
  138. }
  139. func TestDaoSelPointHistory(t *testing.T) {
  140. convey.Convey("SelPointHistory", t, func(ctx convey.C) {
  141. var (
  142. c = context.Background()
  143. mid = int64(0)
  144. startDate xtime.Time
  145. endDate xtime.Time
  146. )
  147. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  148. _, err := d.SelPointHistory(c, mid, startDate, endDate)
  149. ctx.Convey("Then err should be nil.phs should not be nil.", func(ctx convey.C) {
  150. ctx.So(err, convey.ShouldBeNil)
  151. })
  152. })
  153. })
  154. }
  155. func TestDaoExistPointOrder(t *testing.T) {
  156. convey.Convey("ExistPointOrder", t, func(ctx convey.C) {
  157. var (
  158. c = context.Background()
  159. orID = "1"
  160. )
  161. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  162. id, err := d.ExistPointOrder(c, orID)
  163. ctx.Convey("Then err should be nil.id should not be nil.", func(ctx convey.C) {
  164. ctx.So(err, convey.ShouldBeNil)
  165. ctx.So(id, convey.ShouldNotBeNil)
  166. })
  167. })
  168. })
  169. }
  170. func TestDaoAllPointConfig(t *testing.T) {
  171. convey.Convey("AllPointConfig", t, func(ctx convey.C) {
  172. var (
  173. c = context.Background()
  174. )
  175. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  176. res, err := d.AllPointConfig(c)
  177. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  178. ctx.So(err, convey.ShouldBeNil)
  179. ctx.So(res, convey.ShouldNotBeNil)
  180. })
  181. })
  182. })
  183. }
  184. func TestDaoOldPointHistory(t *testing.T) {
  185. convey.Convey("OldPointHistory", t, func(ctx convey.C) {
  186. var (
  187. c = context.Background()
  188. mid = int64(1)
  189. start = int(0)
  190. ps = int(0)
  191. )
  192. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  193. _, err := d.OldPointHistory(c, mid, start, ps)
  194. ctx.Convey("Then err should be nil.phs should not be nil.", func(ctx convey.C) {
  195. ctx.So(err, convey.ShouldBeNil)
  196. })
  197. })
  198. })
  199. }