av_income_test.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package income
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestIncomeGetArchiveStatis(t *testing.T) {
  8. convey.Convey("GetArchiveStatis", t, func(ctx convey.C) {
  9. var (
  10. c = context.Background()
  11. table = "av_income_daily_statis"
  12. query = "id > 0"
  13. from = int(0)
  14. limit = int(10)
  15. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. Exec(c, "INSERT INTO av_income_daily_statis(avs,money_section,money_tips,income,category_id,cdate) VALUES(10, 1, '0-3',1, '2018-01-01')")
  18. avs, err := d.GetArchiveStatis(c, table, query, from, limit)
  19. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(avs, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestIncomeGetArchiveIncome(t *testing.T) {
  27. convey.Convey("GetArchiveIncome av", t, func(ctx convey.C) {
  28. var (
  29. c = context.Background()
  30. id = int64(0)
  31. query = "id > 0"
  32. from = "2018-01-01"
  33. to = "2019-01-01"
  34. limit = int(100)
  35. typ = int(0)
  36. )
  37. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  38. Exec(c, "INSERT INTO av_income(av_id,mid,date) VALUES(1001, 1000, '2018-05-01')")
  39. archs, err := d.GetArchiveIncome(c, id, query, from, to, limit, typ)
  40. ctx.Convey("Then err should be nil.archs should not be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.So(archs, convey.ShouldNotBeNil)
  43. })
  44. })
  45. })
  46. convey.Convey("GetArchiveIncome column", t, func(ctx convey.C) {
  47. var (
  48. c = context.Background()
  49. id = int64(0)
  50. query = "id > 0"
  51. from = "2018-01-01"
  52. to = "2019-01-01"
  53. limit = int(100)
  54. typ = int(2)
  55. )
  56. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  57. Exec(c, "INSERT INTO column_income(aid,mid,date) VALUES(1002, 1000, '2018-05-01')")
  58. archs, err := d.GetArchiveIncome(c, id, query, from, to, limit, typ)
  59. ctx.Convey("Then err should be nil.archs should not be nil.", func(ctx convey.C) {
  60. ctx.So(err, convey.ShouldBeNil)
  61. ctx.So(archs, convey.ShouldNotBeNil)
  62. })
  63. })
  64. })
  65. convey.Convey("GetArchiveIncome bgm", t, func(ctx convey.C) {
  66. var (
  67. c = context.Background()
  68. id = int64(0)
  69. query = "id > 0"
  70. from = "2018-01-01"
  71. to = "2019-01-01"
  72. limit = int(100)
  73. typ = int(3)
  74. )
  75. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  76. Exec(c, "INSERT INTO bgm_income(sid,mid,date) VALUES(1003, 1000, '2018-05-01')")
  77. archs, err := d.GetArchiveIncome(c, id, query, from, to, limit, typ)
  78. ctx.Convey("Then err should be nil.archs should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(archs, convey.ShouldNotBeNil)
  81. })
  82. })
  83. })
  84. convey.Convey("GetArchiveIncome error type", t, func(ctx convey.C) {
  85. var (
  86. c = context.Background()
  87. id = int64(0)
  88. query = "id > 0"
  89. from = "2018-01-01"
  90. to = "2019-01-01"
  91. limit = int(100)
  92. typ = int(4)
  93. )
  94. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  95. _, err := d.GetArchiveIncome(c, id, query, from, to, limit, typ)
  96. ctx.Convey("Then err should be nil.archs should not be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldNotBeNil)
  98. })
  99. })
  100. })
  101. }
  102. func TestIncomeGetAvIncome(t *testing.T) {
  103. convey.Convey("GetAvIncome", t, func(ctx convey.C) {
  104. var (
  105. c = context.Background()
  106. id = int64(0)
  107. query = "id > 0"
  108. from = "2018-01-01"
  109. to = "2019-01-01"
  110. limit = int(100)
  111. typ = int(0)
  112. )
  113. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  114. Exec(c, "INSERT INTO av_income(av_id,mid,date) VALUES(1001, 1000, '2018-05-01')")
  115. avs, err := d.GetAvIncome(c, id, query, from, to, limit, typ)
  116. ctx.Convey("Then err should be nil.avs should not be nil.", func(ctx convey.C) {
  117. ctx.So(err, convey.ShouldBeNil)
  118. ctx.So(avs, convey.ShouldNotBeNil)
  119. })
  120. })
  121. })
  122. }
  123. func TestIncomeGetColumnIncome(t *testing.T) {
  124. convey.Convey("GetColumnIncome", t, func(ctx convey.C) {
  125. var (
  126. c = context.Background()
  127. id = int64(0)
  128. query = "id > 0"
  129. from = "2018-01-01"
  130. to = "2019-01-01"
  131. limit = int(100)
  132. typ = int(2)
  133. )
  134. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  135. Exec(c, "INSERT INTO column_income(aid,mid,date) VALUES(1002, 1000, '2018-05-01')")
  136. columns, err := d.GetColumnIncome(c, id, query, from, to, limit, typ)
  137. ctx.Convey("Then err should be nil.columns should not be nil.", func(ctx convey.C) {
  138. ctx.So(err, convey.ShouldBeNil)
  139. ctx.So(columns, convey.ShouldNotBeNil)
  140. })
  141. })
  142. })
  143. }