statistics_test.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoDelTrend(t *testing.T) {
  9. convey.Convey("DelTrend", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. table = "asc"
  13. limit = int(100)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. d.db.Exec(c, "INSERT INTO up_rating_trend_asc(mid,tag_id) VALUES(1,2) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  17. rows, err := d.DelTrend(c, table, 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 TestDaoInsertRatingStatis(t *testing.T) {
  26. convey.Convey("InsertRatingStatis", t, func(ctx convey.C) {
  27. var (
  28. c = context.Background()
  29. values = "(1,1,'10-20',160,60,50,50,100,100,100,200,2,1,'2018-06-01')"
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. d.db.Exec(c, "DELETE FROM up_rating_statistics WHERE tag_id=2")
  33. _, err := d.InsertRatingStatis(c, values)
  34. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoInsertTopRating(t *testing.T) {
  41. convey.Convey("InsertTopRating", t, func(ctx convey.C) {
  42. var (
  43. c = context.Background()
  44. values = "(1,2,3,100,100,100,'2018-06-01')"
  45. )
  46. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  47. d.db.Exec(c, "DELETE FROM up_rating_top WHERE mid=1")
  48. _, err := d.InsertTopRating(c, values)
  49. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. })
  52. })
  53. })
  54. }
  55. func TestDaoDelRatingCom(t *testing.T) {
  56. convey.Convey("DelRatingCom", t, func(ctx convey.C) {
  57. var (
  58. c = context.Background()
  59. table = "up_rating_top"
  60. date = time.Now()
  61. )
  62. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  63. _, err := d.DelRatingCom(c, table, date, 2000)
  64. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. })
  67. })
  68. })
  69. }