base_test.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoGetBaseInfo(t *testing.T) {
  9. convey.Convey("GetBaseInfo", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. month time.Month = time.June
  13. start = int(0)
  14. end = int(1000)
  15. limit = int(1)
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. d.db.Exec(c, "INSERT INTO up_level_info_06(mid) VALUES(100) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  19. bs, id, err := d.GetBaseInfo(c, month, start, end, limit)
  20. ctx.Convey("Then err should be nil.bs,id should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(id, convey.ShouldNotBeNil)
  23. ctx.So(bs, convey.ShouldNotBeNil)
  24. })
  25. })
  26. })
  27. }
  28. func TestDaoGetBaseTotal(t *testing.T) {
  29. convey.Convey("GetBaseTotal", t, func(ctx convey.C) {
  30. var (
  31. c = context.Background()
  32. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  33. id = int64(0)
  34. limit = int64(100)
  35. )
  36. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  37. d.db.Exec(c, "INSERT INTO up_level_info_06(mid) VALUES(101) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  38. bs, err := d.GetBaseTotal(c, date, id, limit)
  39. ctx.Convey("Then err should be nil.bs should not be nil.", func(ctx convey.C) {
  40. ctx.So(err, convey.ShouldBeNil)
  41. ctx.So(bs, convey.ShouldNotBeNil)
  42. })
  43. })
  44. })
  45. }
  46. func TestDaoBaseInfoStart(t *testing.T) {
  47. convey.Convey("BaseInfoStart", t, func(ctx convey.C) {
  48. var (
  49. c = context.Background()
  50. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. d.db.Exec(c, "INSERT INTO up_level_info_06(mid) VALUES(102) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  54. start, err := d.BaseInfoStart(c, date)
  55. ctx.Convey("Then err should be nil.start should not be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(start, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. func TestDaoBaseInfoEnd(t *testing.T) {
  63. convey.Convey("BaseInfoEnd", t, func(ctx convey.C) {
  64. var (
  65. c = context.Background()
  66. date = time.Date(2018, time.June, 1, 0, 0, 0, 0, time.Local)
  67. )
  68. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  69. d.db.Exec(c, "INSERT INTO up_level_info_06(mid) VALUES(103) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  70. end, err := d.BaseInfoEnd(c, date)
  71. ctx.Convey("Then err should be nil.end should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(end, convey.ShouldNotBeNil)
  74. })
  75. })
  76. })
  77. }