mysql_test.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "go-common/app/job/main/spy/model"
  8. "go-common/library/database/sql"
  9. . "github.com/smartystreets/goconvey/convey"
  10. )
  11. var (
  12. testMysqlMid int64 = 15555180
  13. size = 3
  14. )
  15. func Test_Configs(t *testing.T) {
  16. Convey("Test_Configs info data", t, func() {
  17. res, err := d.Configs(context.TODO())
  18. fmt.Println(res)
  19. So(err, ShouldBeNil)
  20. So(res, ShouldNotBeEmpty)
  21. So(res, ShouldContainKey, model.LimitBlockCount)
  22. So(res, ShouldContainKey, model.LessBlockScore)
  23. So(res, ShouldContainKey, model.AutoBlock)
  24. })
  25. }
  26. func Test_History(t *testing.T) {
  27. Convey("Test_History get history data", t, func() {
  28. res, err := d.History(context.TODO(), testMysqlMid)
  29. fmt.Println(res)
  30. So(err, ShouldBeNil)
  31. So(res, ShouldNotBeEmpty)
  32. })
  33. }
  34. func Test_HistoryList(t *testing.T) {
  35. Convey("Test_HistoryList get history list data", t, func() {
  36. res, err := d.HistoryList(context.TODO(), testMysqlMid, size)
  37. fmt.Println(res)
  38. So(err, ShouldBeNil)
  39. So(res, ShouldNotBeEmpty)
  40. })
  41. }
  42. func Test_TxUpdateUserState(t *testing.T) {
  43. Convey("Test_TxUpdateUserState no err", t, func() {
  44. var (
  45. c = context.TODO()
  46. err error
  47. tx *sql.Tx
  48. ui = &model.UserInfo{Mid: 15555180}
  49. )
  50. tx, err = d.db.Begin(c)
  51. So(err, ShouldBeNil)
  52. ui.State = model.StateNormal
  53. err = d.TxUpdateUserState(context.TODO(), tx, ui)
  54. So(err, ShouldBeNil)
  55. err = tx.Commit()
  56. So(err, ShouldBeNil)
  57. })
  58. }
  59. func Test_TxAddPunishment(t *testing.T) {
  60. Convey("Test_TxAddPunishment add data", t, func() {
  61. var (
  62. c = context.TODO()
  63. err error
  64. tx *sql.Tx
  65. )
  66. tx, err = d.db.Begin(c)
  67. So(err, ShouldBeNil)
  68. err = d.TxAddPunishment(context.TODO(), tx, testMysqlMid, 0, "test封禁", 100000000)
  69. So(err, ShouldBeNil)
  70. err = tx.Commit()
  71. So(err, ShouldBeNil)
  72. })
  73. }
  74. // go test -test.v -test.run Test_Stat
  75. func Test_Stat(t *testing.T) {
  76. Convey("AddIncrStatistics", t, func() {
  77. var (
  78. c = context.TODO()
  79. err error
  80. )
  81. stat := &model.Statistics{
  82. TargetMid: 1,
  83. TargetID: 1,
  84. EventID: 1,
  85. State: 0,
  86. Type: 1,
  87. Quantity: 1,
  88. Ctime: time.Now(),
  89. }
  90. _, err = d.AddIncrStatistics(c, stat)
  91. So(err, ShouldBeNil)
  92. })
  93. Convey("AddStatistics", t, func() {
  94. var (
  95. c = context.TODO()
  96. err error
  97. )
  98. stat := &model.Statistics{
  99. TargetMid: 1,
  100. TargetID: 1,
  101. EventID: 2,
  102. State: 0,
  103. Type: 1,
  104. Quantity: 1,
  105. Ctime: time.Now(),
  106. }
  107. stat.Quantity = 3
  108. _, err = d.AddStatistics(c, stat)
  109. So(err, ShouldBeNil)
  110. })
  111. }
  112. func Test_TxAddEventHistory(t *testing.T) {
  113. Convey("test userinfo", t, func() {
  114. res, err := d.UserInfo(c, 7593623)
  115. So(err, ShouldBeNil)
  116. if res == nil {
  117. _, err = d.db.Exec(c, "insert into spy_user_info_23 (mid) values (7593623)")
  118. So(err, ShouldBeNil)
  119. }
  120. })
  121. var tx *sql.Tx
  122. Convey("Test_TxAddEventHistory start", t, func() {
  123. var err error
  124. tx, err = d.BeginTran(c)
  125. So(err, ShouldBeNil)
  126. })
  127. ueh := &model.UserEventHistory{Mid: 7593634, BaseScore: 100}
  128. Convey("Test_TxAddEventHistory", t, func() {
  129. err := d.TxAddEventHistory(c, tx, ueh)
  130. So(err, ShouldBeNil)
  131. })
  132. Convey("TxUpdateEventScore", t, func() {
  133. err := d.TxUpdateEventScore(c, tx, 7593623, 100, 100)
  134. So(err, ShouldBeNil)
  135. })
  136. Convey("Test_TxAddEventHistory commit", t, func() {
  137. err := tx.Commit()
  138. So(err, ShouldBeNil)
  139. })
  140. Convey("AllEvent", t, func() {
  141. res, err := d.AllEvent(c)
  142. So(err, ShouldBeNil)
  143. So(res, ShouldNotBeNil)
  144. })
  145. Convey("clean data", t, func() {
  146. d.db.Exec(c, "delete from spy_user_event_history_23 where mid = 7593623")
  147. })
  148. }
  149. func Test_SecurityLoginCount(t *testing.T) {
  150. Convey("Test_SecurityLoginCount", t, func() {
  151. _, err := d.SecurityLoginCount(c, 1, "test", time.Now(), time.Now())
  152. So(err, ShouldBeNil)
  153. })
  154. }
  155. func Test_ReBuildMidList(t *testing.T) {
  156. Convey("Test_ReBuildMidList", t, func() {
  157. _, err := d.ReBuildMidList(c, 1, 1, time.Now(), time.Now(), 1)
  158. So(err, ShouldBeNil)
  159. })
  160. }