mysql_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package block
  2. import (
  3. "context"
  4. model "go-common/app/admin/main/member/model/block"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestBlockhistoryIdx(t *testing.T) {
  9. convey.Convey("historyIdx", t, func(ctx convey.C) {
  10. var (
  11. mid = int64(46333)
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1 := historyIdx(mid)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestBlockUser(t *testing.T) {
  22. convey.Convey("User", t, func(ctx convey.C) {
  23. var (
  24. c = context.Background()
  25. mid = int64(46333)
  26. )
  27. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  28. user, err := d.User(c, mid)
  29. ctx.Convey("Then err should be nil.user should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. ctx.So(user, convey.ShouldNotBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestBlockUsers(t *testing.T) {
  37. convey.Convey("Users", t, func(ctx convey.C) {
  38. var (
  39. c = context.Background()
  40. mids = []int64{46333}
  41. )
  42. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  43. users, err := d.Users(c, mids)
  44. ctx.Convey("Then err should be nil.users should not be nil.", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. ctx.So(users, convey.ShouldNotBeNil)
  47. })
  48. })
  49. })
  50. }
  51. func TestBlockTxUpdateUser(t *testing.T) {
  52. convey.Convey("TxUpdateUser", t, func(ctx convey.C) {
  53. var (
  54. c = context.Background()
  55. tx, _ = d.BeginTX(c)
  56. mid = int64(46333)
  57. status model.BlockStatus = model.BlockStatusFalse
  58. )
  59. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  60. err := d.TxUpdateUser(c, tx, mid, status)
  61. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  62. ctx.So(err, convey.ShouldBeNil)
  63. })
  64. })
  65. ctx.Reset(func() {
  66. tx.Commit()
  67. })
  68. })
  69. }
  70. func TestBlockUserDetails(t *testing.T) {
  71. convey.Convey("UserDetails", t, func(ctx convey.C) {
  72. var (
  73. c = context.Background()
  74. mids = []int64{46333}
  75. )
  76. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  77. users, err := d.UserDetails(c, mids)
  78. ctx.Convey("Then err should be nil.users should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(users, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. }
  85. func TestBlockUpdateAddBlockCount(t *testing.T) {
  86. convey.Convey("UpdateAddBlockCount", t, func(ctx convey.C) {
  87. var (
  88. c = context.Background()
  89. mid = int64(46333)
  90. )
  91. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  92. err := d.UpdateAddBlockCount(c, mid)
  93. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. })
  96. })
  97. })
  98. }
  99. func TestBlockHistory(t *testing.T) {
  100. convey.Convey("History", t, func(ctx convey.C) {
  101. var (
  102. c = context.Background()
  103. mid = int64(46333)
  104. start = int(0)
  105. limit = int(10)
  106. desc bool
  107. )
  108. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  109. history, err := d.History(c, mid, start, limit, desc)
  110. ctx.Convey("Then err should be nil.history should not be nil.", func(ctx convey.C) {
  111. ctx.So(err, convey.ShouldBeNil)
  112. ctx.So(history, convey.ShouldNotBeNil)
  113. })
  114. })
  115. })
  116. }
  117. func TestBlockHistoryCount(t *testing.T) {
  118. convey.Convey("HistoryCount", t, func(ctx convey.C) {
  119. var (
  120. c = context.Background()
  121. mid = int64(46333)
  122. )
  123. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  124. total, err := d.HistoryCount(c, mid)
  125. ctx.Convey("Then err should be nil.total should not be nil.", func(ctx convey.C) {
  126. ctx.So(err, convey.ShouldBeNil)
  127. ctx.So(total, convey.ShouldNotBeNil)
  128. })
  129. })
  130. })
  131. }
  132. func TestBlockTxInsertHistory(t *testing.T) {
  133. convey.Convey("TxInsertHistory", t, func(ctx convey.C) {
  134. var (
  135. c = context.Background()
  136. tx, _ = d.BeginTX(c)
  137. h = &model.DBHistory{}
  138. )
  139. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  140. err := d.TxInsertHistory(c, tx, h)
  141. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  142. ctx.So(err, convey.ShouldBeNil)
  143. })
  144. })
  145. ctx.Reset(func() {
  146. tx.Commit()
  147. })
  148. })
  149. }
  150. func TestBlockintsToStrs(t *testing.T) {
  151. convey.Convey("intsToStrs", t, func(ctx convey.C) {
  152. var (
  153. ints = []int64{46333}
  154. )
  155. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  156. strs := intsToStrs(ints)
  157. ctx.Convey("Then strs should not be nil.", func(ctx convey.C) {
  158. ctx.So(strs, convey.ShouldNotBeNil)
  159. })
  160. })
  161. })
  162. }