mysql_test.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. package dao
  2. import (
  3. "context"
  4. "math/rand"
  5. "testing"
  6. "time"
  7. "go-common/app/service/main/vip/model"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoOldInsertVipBcoinSalary(t *testing.T) {
  11. var (
  12. c = context.TODO()
  13. r = &model.VipBcoinSalary{}
  14. )
  15. r.Amount = 10
  16. r.Status = 0
  17. r.Mid = 1
  18. r.Memo = "年费会员发放B币"
  19. r.GiveNowStatus = 0
  20. convey.Convey("OldInsertVipBcoinSalary,should return true where err == nil", t, func(ctx convey.C) {
  21. err := d.OldInsertVipBcoinSalary(c, r)
  22. ctx.Convey("Error should be nil", func(ctx convey.C) {
  23. ctx.So(err, convey.ShouldBeNil)
  24. })
  25. })
  26. }
  27. func TestDaoSelAllConfig(t *testing.T) {
  28. var (
  29. c = context.TODO()
  30. )
  31. convey.Convey("SelAllConfig, should return true where err == nil and res not empty", t, func(ctx convey.C) {
  32. res, err := d.SelAllConfig(c)
  33. ctx.Convey("Error should be nil", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. })
  36. ctx.Convey("res should not be nil", func(ctx convey.C) {
  37. ctx.So(res, convey.ShouldNotBeNil)
  38. })
  39. })
  40. }
  41. func TestDaoSelVipAppInfo(t *testing.T) {
  42. var (
  43. c = context.TODO()
  44. no = int(0)
  45. )
  46. convey.Convey("SelVipAppInfo", t, func(ctx convey.C) {
  47. _, err := d.SelVipAppInfo(c, no)
  48. ctx.Convey("Error should be nil", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. })
  51. })
  52. }
  53. func TestDaoOldSelLastBcoin(t *testing.T) {
  54. var (
  55. c = context.TODO()
  56. mid = int64(1)
  57. )
  58. convey.Convey("OldSelLastBcoin,should return true where err == nil and r != nil", t, func(ctx convey.C) {
  59. r, err := d.OldSelLastBcoin(c, mid)
  60. ctx.Convey("Error should be nil", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. ctx.Convey("r should not be nil", func(ctx convey.C) {
  64. ctx.So(r, convey.ShouldNotBeNil)
  65. })
  66. })
  67. }
  68. func TestDaoSelBusiness(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. id = int64(4)
  72. )
  73. convey.Convey("SelBusiness,should return true where err == nil and r != nil", t, func(ctx convey.C) {
  74. _, err := d.SelBusiness(c, id)
  75. ctx.Convey("Error should be nil", func(ctx convey.C) {
  76. ctx.So(err, convey.ShouldBeNil)
  77. })
  78. })
  79. }
  80. func TestDaoSelResourcePool(t *testing.T) {
  81. var (
  82. c = context.TODO()
  83. id = int64(5)
  84. )
  85. convey.Convey("SelResourcePool", t, func(ctx convey.C) {
  86. _, err := d.SelResourcePool(c, id)
  87. ctx.Convey("Error should be nil", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. })
  90. })
  91. }
  92. func TestDaoOldSelVipUserInfo(t *testing.T) {
  93. var (
  94. c = context.TODO()
  95. mid = int64(1)
  96. )
  97. convey.Convey("OldSelVipUserInfo", t, func(ctx convey.C) {
  98. _, err := d.OldSelVipUserInfo(c, mid)
  99. ctx.Convey("Error should be nil", func(ctx convey.C) {
  100. ctx.So(err, convey.ShouldBeNil)
  101. })
  102. })
  103. }
  104. func TestDaoSelVipResourceBatch(t *testing.T) {
  105. var (
  106. c = context.TODO()
  107. id = int64(5)
  108. )
  109. convey.Convey("SelVipResourceBatch,should return true where err == nil and r != nil", t, func(ctx convey.C) {
  110. _, err := d.SelVipResourceBatch(c, id)
  111. ctx.Convey("Error should be nil", func(ctx convey.C) {
  112. ctx.So(err, convey.ShouldBeNil)
  113. })
  114. })
  115. }
  116. func TestDaoOldSelVipChangeHistory(t *testing.T) {
  117. var (
  118. c = context.TODO()
  119. relationID = "ad4bb9b8f5d9d4a7123459780"
  120. batchID int64 = 1
  121. )
  122. convey.Convey("OldSelVipChangeHistory", t, func(ctx convey.C) {
  123. _, err := d.OldVipchangeHistory(c, relationID, batchID)
  124. ctx.Convey("Error should be nil", func(ctx convey.C) {
  125. ctx.So(err, convey.ShouldBeNil)
  126. })
  127. })
  128. }
  129. func TestDaoOldUpdateVipUserInfo(t *testing.T) {
  130. var (
  131. c = context.TODO()
  132. r = &model.VipUserInfo{Mid: rand.Int63()}
  133. )
  134. convey.Convey("OldUpdateVipUserInfo", t, func(ctx convey.C) {
  135. tx, err := d.StartTx(c)
  136. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  137. ctx.So(err, convey.ShouldBeNil)
  138. })
  139. defer tx.Commit()
  140. a, err := d.OldUpdateVipUserInfo(c, tx, r)
  141. ctx.Convey("Error should be nil", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. })
  144. ctx.Convey("a should not be nil", func(ctx convey.C) {
  145. ctx.So(a, convey.ShouldNotBeNil)
  146. })
  147. })
  148. }
  149. func TestDaoUpdateBatchCount3(t *testing.T) {
  150. var (
  151. c = context.TODO()
  152. r = &model.VipResourceBatch{ID: 1}
  153. ver = int64(0)
  154. )
  155. convey.Convey("UpdateBatchCount", t, func(ctx convey.C) {
  156. tx, err := d.StartTx(c)
  157. ctx.So(err, convey.ShouldBeNil)
  158. defer tx.Commit()
  159. a, err := d.UpdateBatchCount(c, tx, r, ver)
  160. ctx.So(err, convey.ShouldBeNil)
  161. ctx.So(a, convey.ShouldBeGreaterThan, 0)
  162. })
  163. }
  164. func TestDaoOldInsertVipUserInfo(t *testing.T) {
  165. var (
  166. c = context.TODO()
  167. r = &model.VipUserInfo{Mid: time.Now().Unix()}
  168. )
  169. convey.Convey("OldInsertVipUserInfo", t, func(ctx convey.C) {
  170. tx, err := d.OldStartTx(c)
  171. ctx.So(err, convey.ShouldBeNil)
  172. err = d.OldInsertVipUserInfo(c, tx, r)
  173. ctx.So(err, convey.ShouldBeNil)
  174. })
  175. }
  176. func TestDaoOldInsertVipChangeHistory(t *testing.T) {
  177. var (
  178. c = context.TODO()
  179. r = &model.VipChangeHistory{}
  180. )
  181. convey.Convey("OldInsertVipChangeHistory", t, func(ctx convey.C) {
  182. tx, err := d.OldStartTx(c)
  183. ctx.Convey("Tx Error should be nil", func(ctx convey.C) {
  184. ctx.So(err, convey.ShouldBeNil)
  185. })
  186. id, err := d.OldInsertVipChangeHistory(c, tx, r)
  187. ctx.Convey("Error should be nil", func(ctx convey.C) {
  188. ctx.So(err, convey.ShouldBeNil)
  189. })
  190. ctx.Convey("id should not be nil", func(ctx convey.C) {
  191. ctx.So(id, convey.ShouldNotBeNil)
  192. })
  193. })
  194. }
  195. func TestDao_OldTxDelBcoinSalary(t *testing.T) {
  196. convey.Convey("old tx del bcoin salary", t, func() {
  197. tx, _ := d.OldStartTx(context.TODO())
  198. err := d.OldTxDelBcoinSalary(tx, 106138791, time.Now().AddDate(0, 1, 0))
  199. tx.Commit()
  200. convey.So(err, convey.ShouldBeNil)
  201. })
  202. }