up_income_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package income
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestIncomeUpIncomeCount(t *testing.T) {
  8. convey.Convey("UpIncomeCount", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. table = "up_income"
  12. query = "id > 0"
  13. )
  14. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  15. Exec(c, "INSERT INTO up_income(mid, income, date) VALUS(1993, 10, '2018-01-01')")
  16. count, err := d.UpIncomeCount(c, table, 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. convey.Convey("UpIncomeCount table error", t, func(ctx convey.C) {
  24. var (
  25. c = context.Background()
  26. table = ""
  27. query = ""
  28. )
  29. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  30. _, err := d.UpIncomeCount(c, table, query)
  31. ctx.Convey("Then err should be nil.count should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldNotBeNil)
  33. })
  34. })
  35. })
  36. }
  37. func TestIncomeGetUpIncome(t *testing.T) {
  38. convey.Convey("GetUpIncome", t, func(ctx convey.C) {
  39. var (
  40. c = context.Background()
  41. table = "up_income"
  42. incomeType = "av_income"
  43. query = "is_deleted = 0"
  44. id = int64(0)
  45. limit = int(10)
  46. )
  47. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  48. upIncome, err := d.GetUpIncome(c, table, incomeType, query, id, limit)
  49. ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
  50. ctx.So(err, convey.ShouldBeNil)
  51. ctx.So(upIncome, convey.ShouldNotBeNil)
  52. })
  53. })
  54. })
  55. convey.Convey("GetUpIncome query == nil", t, func(ctx convey.C) {
  56. var (
  57. c = context.Background()
  58. table = "up_income"
  59. incomeType = "av_income"
  60. query = ""
  61. id = int64(0)
  62. limit = int(10)
  63. )
  64. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  65. _, err := d.GetUpIncome(c, table, incomeType, query, id, limit)
  66. ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldNotBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestIncomeGetUpIncomeBySort(t *testing.T) {
  73. convey.Convey("GetUpIncomeBySort", t, func(ctx convey.C) {
  74. var (
  75. c = context.Background()
  76. table = "up_income"
  77. typeField = "av_income,av_tax,av_base_income,av_total_income"
  78. sort = "id"
  79. query = "id > 0"
  80. from = int(0)
  81. limit = int(10)
  82. )
  83. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  84. upIncome, err := d.GetUpIncomeBySort(c, table, typeField, sort, query, from, limit)
  85. ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. ctx.So(upIncome, convey.ShouldNotBeNil)
  88. })
  89. })
  90. })
  91. convey.Convey("GetUpIncomeBySort table == nil", t, func(ctx convey.C) {
  92. var (
  93. c = context.Background()
  94. table = ""
  95. typeField = "av_income"
  96. sort = "id"
  97. query = "id > 0"
  98. from = int(0)
  99. limit = int(10)
  100. )
  101. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  102. _, err := d.GetUpIncomeBySort(c, table, typeField, sort, query, from, limit)
  103. ctx.Convey("Then err should be nil.upIncome should not be nil.", func(ctx convey.C) {
  104. ctx.So(err, convey.ShouldNotBeNil)
  105. })
  106. })
  107. })
  108. }
  109. func TestIncomeGetUpDailyStatis(t *testing.T) {
  110. convey.Convey("GetUpDailyStatis", t, func(ctx convey.C) {
  111. var (
  112. c = context.Background()
  113. table = "up_income_daily_statis"
  114. fromTime = "2018-01-01"
  115. toTime = "2018-01-10"
  116. )
  117. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  118. Exec(c, "INSERT INTO up_income_daily_statis(ups, cdate) VALUES(10, '2018-01-02')")
  119. s, err := d.GetUpDailyStatis(c, table, fromTime, toTime)
  120. ctx.Convey("Then err should be nil.s should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(s, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }