email_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "time"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestDaoTotalIncome(t *testing.T) {
  10. convey.Convey("TotalIncome", t, func(ctx convey.C) {
  11. var (
  12. c = context.Background()
  13. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  14. from = int64(0)
  15. limit = int64(100)
  16. )
  17. fmt.Println("date:", date)
  18. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  19. Exec(c, "INSERT INTO av_income(av_id,mid,income,date) VALUES (1,2,3,'2018-06-24') ON DUPLICATE KEY UPDATE av_id=VALUES(av_id), date=VALUES(date)")
  20. infos, err := d.TotalIncome(c, date, from, limit)
  21. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  22. ctx.So(err, convey.ShouldBeNil)
  23. ctx.So(infos, convey.ShouldNotBeNil)
  24. })
  25. })
  26. })
  27. }
  28. func TestDaoGetAV(t *testing.T) {
  29. convey.Convey("GetAV", t, func(ctx convey.C) {
  30. var (
  31. c = context.Background()
  32. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. Exec(c, "INSERT INTO av_income(av_id, mid, income, date) VALUES (1,2,3,'2018-06-24') ON DUPLICATE KEY UPDATE av_id=VALUES(av_id), date=VALUES(date)")
  36. infos, err := d.GetAV(c, date)
  37. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. ctx.So(infos, convey.ShouldNotBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestDaoGetTag(t *testing.T) {
  45. convey.Convey("GetTag", t, func(ctx convey.C) {
  46. var (
  47. c = context.Background()
  48. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  49. )
  50. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  51. Exec(c, "INSERT INTO tag_info(tag,category_id,is_common,date) VALUES(2,3,1, '2018-06-24')")
  52. infos, err := d.GetTag(c, date)
  53. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. ctx.So(infos, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestDaoGetMID(t *testing.T) {
  61. convey.Convey("GetMID", t, func(ctx convey.C) {
  62. var (
  63. c = context.Background()
  64. TagID = int64(10)
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. Exec(c, "INSERT INTO tag_up_info(mid) VALUES(10) ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  68. infos, err := d.GetMID(c, TagID)
  69. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. ctx.So(infos, convey.ShouldNotBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoTagToAV(t *testing.T) {
  77. convey.Convey("TagToAV", t, func(ctx convey.C) {
  78. var (
  79. c = context.Background()
  80. category = int(2)
  81. date = time.Now()
  82. )
  83. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  84. infos, err := d.TagToAV(c, category, date)
  85. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. ctx.So(infos, convey.ShouldNotBeNil)
  88. })
  89. })
  90. })
  91. }
  92. func TestDaoMIDToAV(t *testing.T) {
  93. convey.Convey("MIDToAV", t, func(ctx convey.C) {
  94. var (
  95. c = context.Background()
  96. mid = int64(100)
  97. category = int(10)
  98. date = time.Now()
  99. )
  100. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  101. infos, err := d.MIDToAV(c, mid, category, date)
  102. ctx.Convey("Then err should be nil.infos should not be nil.", func(ctx convey.C) {
  103. ctx.So(err, convey.ShouldBeNil)
  104. ctx.So(infos, convey.ShouldNotBeNil)
  105. })
  106. })
  107. })
  108. }