past_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoDelPastRecord(t *testing.T) {
  9. convey.Convey("DelPastRecord", 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. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. d.db.Exec(c, "INSERT INTO past_rating_record(times,date) VALUES(1, '2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  16. rows, err := d.DelPastRecord(c, date)
  17. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. ctx.So(rows, convey.ShouldNotBeNil)
  20. })
  21. })
  22. })
  23. }
  24. func TestDaoGetPastRecord(t *testing.T) {
  25. convey.Convey("GetPastRecord", t, func(ctx convey.C) {
  26. var (
  27. c = context.Background()
  28. cdate = "2018-06-01"
  29. )
  30. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  31. d.db.Exec(c, "INSERT INTO past_rating_record(times,date) VALUES(1, '2018-06-01') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  32. times, err := d.GetPastRecord(c, cdate)
  33. ctx.Convey("Then err should be nil.times should not be nil.", func(ctx convey.C) {
  34. ctx.So(err, convey.ShouldBeNil)
  35. ctx.So(times, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoInsertPastRecord(t *testing.T) {
  41. convey.Convey("InsertPastRecord", t, func(ctx convey.C) {
  42. var (
  43. c = context.Background()
  44. times = int(1)
  45. cdate = "2018-06-01"
  46. )
  47. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  48. rows, err := d.InsertPastRecord(c, times, cdate)
  49. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. ctx.So(rows, convey.ShouldNotBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestDaoInsertPastScoreStat(t *testing.T) {
  57. convey.Convey("InsertPastScoreStat", t, func(ctx convey.C) {
  58. var (
  59. c = context.Background()
  60. values = "(1, 100, 100, 100)"
  61. )
  62. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  63. rows, err := d.InsertPastScoreStat(c, values)
  64. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  65. ctx.So(err, convey.ShouldBeNil)
  66. ctx.So(rows, convey.ShouldNotBeNil)
  67. })
  68. })
  69. })
  70. }
  71. func TestDaoGetPasts(t *testing.T) {
  72. convey.Convey("GetPasts", t, func(ctx convey.C) {
  73. var (
  74. c = context.Background()
  75. offset = int64(0)
  76. limit = int64(1000)
  77. )
  78. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  79. d.db.Exec(c, "INSERT INTO past_score_statistics(mid) VALUES(1) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  80. past, last, err := d.GetPasts(c, offset, limit)
  81. ctx.Convey("Then err should be nil.past,last should not be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. ctx.So(last, convey.ShouldNotBeNil)
  84. ctx.So(past, convey.ShouldNotBeNil)
  85. })
  86. })
  87. })
  88. }
  89. func TestDaoDelPastStat(t *testing.T) {
  90. convey.Convey("DelPastStat", t, func(ctx convey.C) {
  91. var (
  92. c = context.Background()
  93. limit = int64(0)
  94. )
  95. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  96. d.db.Exec(c, "INSERT INTO past_score_statistics(mid) VALUES(1) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  97. rows, err := d.DelPastStat(c, limit)
  98. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  99. ctx.So(err, convey.ShouldBeNil)
  100. ctx.So(rows, convey.ShouldNotBeNil)
  101. })
  102. })
  103. })
  104. }