rating_test.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoDelRatings(t *testing.T) {
  9. convey.Convey("DelRatings", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  13. limit = int(10)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  17. rows, err := d.DelRatings(c, date, limit)
  18. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(rows, convey.ShouldNotBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoRatingStart(t *testing.T) {
  26. convey.Convey("RatingStart", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  33. start, err := d.RatingStart(c, date)
  34. ctx.Convey("Then err should be nil.start should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(start, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoRatingEnd(t *testing.T) {
  42. convey.Convey("RatingEnd", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  46. )
  47. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  48. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  49. end, err := d.RatingEnd(c, date)
  50. ctx.Convey("Then err should be nil.end should not be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. ctx.So(end, convey.ShouldNotBeNil)
  53. })
  54. })
  55. })
  56. }
  57. func TestDaoRatingCount(t *testing.T) {
  58. convey.Convey("RatingCount", t, func(ctx convey.C) {
  59. var (
  60. c = context.Background()
  61. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  62. )
  63. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  64. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  65. count, err := d.RatingCount(c, date)
  66. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. ctx.So(count, convey.ShouldNotBeNil)
  69. })
  70. })
  71. })
  72. }
  73. func TestDaoGetRatings(t *testing.T) {
  74. convey.Convey("GetRatings", t, func(ctx convey.C) {
  75. var (
  76. c = context.Background()
  77. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  78. offset = int(0)
  79. limit = int(100)
  80. )
  81. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  82. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  83. rs, last, err := d.GetRatings(c, date, offset, limit)
  84. ctx.Convey("Then err should be nil.rs,last should not be nil.", func(ctx convey.C) {
  85. ctx.So(err, convey.ShouldBeNil)
  86. ctx.So(last, convey.ShouldNotBeNil)
  87. ctx.So(rs, convey.ShouldNotBeNil)
  88. })
  89. })
  90. })
  91. }
  92. func TestDaoGetRatingsFast(t *testing.T) {
  93. convey.Convey("GetRatingsFast", t, func(ctx convey.C) {
  94. var (
  95. c = context.Background()
  96. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  97. start = int(0)
  98. end = int(10000)
  99. limit = int(10)
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. d.db.Exec(c, "INSERT INTO up_rating_06(mid,cdate) VALUES(1,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  103. rs, id, err := d.GetRatingsFast(c, date, start, end, limit)
  104. ctx.Convey("Then err should be nil.rs,id should not be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. ctx.So(id, convey.ShouldNotBeNil)
  107. ctx.So(rs, convey.ShouldNotBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDaoInsertRatingStat(t *testing.T) {
  113. convey.Convey("InsertRatingStat", t, func(ctx convey.C) {
  114. var (
  115. c = context.Background()
  116. month time.Month = time.June
  117. values = "(1,2,'2018-06-01',100,100,100,600,600,300)"
  118. )
  119. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  120. _, err := d.InsertRatingStat(c, month, values)
  121. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  122. ctx.So(err, convey.ShouldBeNil)
  123. })
  124. })
  125. })
  126. }