statistics_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaoAscTrendCount(t *testing.T) {
  8. convey.Convey("AscTrendCount", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. date = "2018-06-01"
  12. query = ""
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. d.db.Exec(c, "INSERT INTO up_rating_trend_asc(mid) VALUES(1001) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  16. count, err := d.AscTrendCount(c, date, query)
  17. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(count, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoDescTrendCount(t *testing.T) {
  25. convey.Convey("DescTrendCount", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. date = "2018-06-01"
  29. query = ""
  30. )
  31. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  32. d.db.Exec(c, "INSERT INTO up_rating_trend_desc(mid) VALUES(1001) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  33. count, err := d.DescTrendCount(c, date, query)
  34. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  35. ctx.So(err, convey.ShouldBeNil)
  36. ctx.So(count, convey.ShouldNotBeNil)
  37. })
  38. })
  39. })
  40. }
  41. func TestDaoGetRatingStatis(t *testing.T) {
  42. convey.Convey("GetRatingStatis", t, func(ctx convey.C) {
  43. var (
  44. c = context.Background()
  45. ctype = int64(0)
  46. date = "2018-06-01"
  47. query = "2"
  48. )
  49. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  50. d.db.Exec(c, "INSERT INTO up_rating_statistics(cdate,tag_id,ctype,section) VALUES('2018-06-01',2,2,1) ON DUPLICATE KEY UPDATE tag_id=VALUES(tag_id)")
  51. statis, err := d.GetRatingStatis(c, ctype, date, query)
  52. ctx.Convey("Then err should be nil.statis should not be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. ctx.So(statis, convey.ShouldNotBeNil)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoGetTrendAsc(t *testing.T) {
  60. convey.Convey("GetTrendAsc", t, func(ctx convey.C) {
  61. var (
  62. c = context.Background()
  63. ctype = "magnetic"
  64. date = "2018-06-01"
  65. query = ""
  66. )
  67. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  68. d.db.Exec(c, "INSERT INTO up_rating_trend_asc(mid,date) VALUES(1001,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  69. ts, err := d.GetTrendAsc(c, ctype, date, query)
  70. ctx.Convey("Then err should be nil.ts should not be nil.", func(ctx convey.C) {
  71. ctx.So(err, convey.ShouldBeNil)
  72. ctx.So(ts, convey.ShouldNotBeNil)
  73. })
  74. })
  75. })
  76. }
  77. func TestDaoGetTrendDesc(t *testing.T) {
  78. convey.Convey("GetTrendDesc", t, func(ctx convey.C) {
  79. var (
  80. c = context.Background()
  81. ctype = "magnetic"
  82. date = "2018-06-01"
  83. query = ""
  84. )
  85. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  86. d.db.Exec(c, "INSERT INTO up_rating_trend_desc(mid,date) VALUES(1001,'2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  87. ts, err := d.GetTrendDesc(c, ctype, date, query)
  88. ctx.Convey("Then err should be nil.ts should not be nil.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldBeNil)
  90. ctx.So(ts, convey.ShouldNotBeNil)
  91. })
  92. })
  93. })
  94. }