mysql_test.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/job/main/credit-timer/model"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func Test_UpdateKPI(t *testing.T) {
  10. r := &model.Kpi{}
  11. r.Day = time.Now()
  12. r.Mid = 111
  13. r.Rate = 1
  14. r.Rank = 10
  15. r.RankPer = 10
  16. r.RankTotal = 100
  17. Convey("should return err be nil", t, func() {
  18. err := d.UpdateKPI(context.TODO(), r)
  19. So(err, ShouldBeNil)
  20. })
  21. }
  22. func Test_UpdateKPIData(t *testing.T) {
  23. r := &model.KpiData{}
  24. r.Day = time.Now()
  25. r.Mid = 111
  26. Convey("should return err be nil", t, func() {
  27. err := d.UpdateKPIData(context.TODO(), r)
  28. So(err, ShouldBeNil)
  29. })
  30. }
  31. func Test_UpdateKPIPoint(t *testing.T) {
  32. r := &model.KpiPoint{}
  33. r.Day = time.Now()
  34. r.Mid = 1
  35. r.Point = 100
  36. r.ActiveDays = 10
  37. r.BlockedTotal = 11
  38. r.VoteRadio = 60
  39. r.VoteTotal = 1000
  40. Convey("should return err be nil", t, func() {
  41. err := d.UpdateKPIPoint(context.TODO(), r)
  42. So(err, ShouldBeNil)
  43. })
  44. }
  45. func Test_UpdateCaseEndTime(t *testing.T) {
  46. Convey("should return err be nil", t, func() {
  47. num, err := d.UpdateCaseEndTime(context.TODO(), time.Now())
  48. So(err, ShouldBeNil)
  49. So(num, ShouldBeGreaterThanOrEqualTo, 0)
  50. })
  51. }
  52. func Test_UpdateCaseEndVote(t *testing.T) {
  53. Convey("should return err be nil", t, func() {
  54. num, err := d.UpdateCaseEndVote(context.TODO(), 600, time.Now().Add(time.Minute*10))
  55. So(err, ShouldBeNil)
  56. So(num, ShouldBeGreaterThanOrEqualTo, 0)
  57. })
  58. }
  59. func Test_UpdateJury(t *testing.T) {
  60. Convey("should return err be nil", t, func() {
  61. num, err := d.UpdateJury(context.TODO(), time.Now())
  62. So(err, ShouldBeNil)
  63. So(num, ShouldBeGreaterThanOrEqualTo, 0)
  64. })
  65. }
  66. func Test_UpdateJuryExpired(t *testing.T) {
  67. Convey("should return err be nil", t, func() {
  68. err := d.UpdateJuryExpired(context.TODO(), 88889017, time.Now())
  69. So(err, ShouldBeNil)
  70. })
  71. }
  72. func Test_UpdateVote(t *testing.T) {
  73. Convey("should return err be nil", t, func() {
  74. num, err := d.UpdateVote(context.TODO(), time.Now())
  75. So(err, ShouldBeNil)
  76. So(num, ShouldBeGreaterThanOrEqualTo, 0)
  77. })
  78. }
  79. func Test_LoadConf(t *testing.T) {
  80. Convey("should return err be nil", t, func() {
  81. vTotal, err := d.LoadConf(context.TODO())
  82. So(err, ShouldBeNil)
  83. So(vTotal, ShouldBeGreaterThanOrEqualTo, 0)
  84. })
  85. }
  86. func Test_JuryList(t *testing.T) {
  87. Convey("should return err be nil", t, func() {
  88. mids, err := d.JuryList(context.TODO())
  89. So(err, ShouldBeNil)
  90. So(mids, ShouldNotResemble, []int64{})
  91. })
  92. }
  93. func Test_JuryKPI(t *testing.T) {
  94. begin := time.Now().Format("2006-01-02")
  95. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  96. Convey("should return err be nil", t, func() {
  97. res, err := d.JuryKPI(context.TODO(), begin, end)
  98. So(err, ShouldBeNil)
  99. So(res, ShouldNotResemble, []int64{})
  100. })
  101. }
  102. func Test_CountVoteTotal(t *testing.T) {
  103. begin := time.Now().Format("2006-01-02")
  104. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  105. Convey("should return err be nil", t, func() {
  106. count, err := d.CountVoteTotal(context.TODO(), 88889017, begin, end)
  107. So(err, ShouldBeNil)
  108. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  109. })
  110. }
  111. func Test_CountVoteRightViolate(t *testing.T) {
  112. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  113. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  114. Convey("should return err be nil", t, func() {
  115. count, err := d.CountVoteRightViolate(context.TODO(), 88889017, begin, end)
  116. So(err, ShouldBeNil)
  117. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  118. })
  119. }
  120. func Test_CountVoteRightLegal(t *testing.T) {
  121. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  122. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  123. Convey("should return err be nil", t, func() {
  124. count, err := d.CountVoteRightLegal(context.TODO(), 88889017, begin, end)
  125. So(err, ShouldBeNil)
  126. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  127. })
  128. }
  129. func Test_CountBlocked(t *testing.T) {
  130. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  131. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  132. Convey("should return err be nil", t, func() {
  133. count, err := d.CountBlocked(context.TODO(), 88889017, begin, end)
  134. So(err, ShouldBeNil)
  135. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  136. })
  137. }
  138. func Test_KpiPointDay(t *testing.T) {
  139. day := time.Now().Format("2006-01-02")
  140. Convey("should return err be nil", t, func() {
  141. _, err := d.KPIPointDay(context.TODO(), day)
  142. So(err, ShouldBeNil)
  143. // So(kp, ShouldNotBeNil)
  144. // So(kp, ShouldResemble,[]model.KpiPoint{})
  145. })
  146. }
  147. func TestDao_KPIPoint(t *testing.T) {
  148. day := time.Now().Format("2006-01-02")
  149. Convey("should return err be nil", t, func() {
  150. kp, _ := d.KPIPoint(context.TODO(), 88889017, day)
  151. // So(err, ShouldBeNil)
  152. So(kp, ShouldNotBeNil)
  153. So(kp, ShouldResemble, model.KpiPoint{})
  154. })
  155. }
  156. func Test_KPIList(t *testing.T) {
  157. Convey("should return err be nil", t, func() {
  158. kpis, err := d.KPIList(context.TODO(), 88889017)
  159. So(err, ShouldBeNil)
  160. So(kpis, ShouldNotBeNil)
  161. // So(kpis, ShouldResemble,[]model.Kpi{})
  162. })
  163. }
  164. func Test_CountVoteActive(t *testing.T) {
  165. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  166. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  167. Convey("should return err be nil", t, func() {
  168. count, err := d.CountVoteActive(context.TODO(), 88889017, begin, end)
  169. So(err, ShouldBeNil)
  170. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  171. })
  172. }
  173. func TestDao_CountOpinion(t *testing.T) {
  174. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  175. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  176. Convey("should return err be nil", t, func() {
  177. count, err := d.CountOpinion(context.TODO(), 88889017, begin, end)
  178. So(err, ShouldBeNil)
  179. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  180. })
  181. }
  182. func Test_OpinionQuality(t *testing.T) {
  183. begin := time.Now().AddDate(0, 0, -30).Format("2006-01-02")
  184. end := time.Now().AddDate(0, 0, 1).Format("2006-01-02")
  185. Convey("should return err be nil", t, func() {
  186. likes, hates, err := d.OpinionQuality(context.TODO(), 88889017, begin, end)
  187. So(err, ShouldBeNil)
  188. So(likes, ShouldBeGreaterThanOrEqualTo, 0)
  189. So(hates, ShouldBeGreaterThanOrEqualTo, 0)
  190. })
  191. }
  192. func Test_CountVoteByTime(t *testing.T) {
  193. begin := time.Now().AddDate(0, 0, -30)
  194. end := time.Now().AddDate(0, 0, 1)
  195. Convey("should return err be nil", t, func() {
  196. count, err := d.CountVoteByTime(context.TODO(), 88889017, begin, end)
  197. So(err, ShouldBeNil)
  198. So(count, ShouldBeGreaterThanOrEqualTo, 0)
  199. })
  200. }