column_charge_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package charge
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestChargeColumnCharge(t *testing.T) {
  9. convey.Convey("ColumnCharge", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  13. id = int64(0)
  14. limit = int(100)
  15. table = "column_weekly_charge"
  16. )
  17. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  18. d.db.Exec(c, "INSERT INTO column_weekly_charge(aid,mid,date) VALUES(1,2,'2018-06-24')")
  19. columns, err := d.ColumnCharge(c, date, id, limit, table)
  20. ctx.Convey("Then err should be nil.columns should not be nil.", func(ctx convey.C) {
  21. ctx.So(err, convey.ShouldBeNil)
  22. ctx.So(columns, convey.ShouldNotBeNil)
  23. })
  24. })
  25. })
  26. }
  27. func TestChargeCmStatis(t *testing.T) {
  28. convey.Convey("CmStatis", t, func(ctx convey.C) {
  29. var (
  30. c = context.Background()
  31. id = int64(0)
  32. limit = int(100)
  33. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. d.db.Exec(c, "INSERT INTO column_charge_statis(aid,mid) VALUES(1,2)")
  36. columns, err := d.CmStatis(c, id, limit)
  37. ctx.Convey("Then err should be nil.columns should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. ctx.So(columns, convey.ShouldNotBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestChargeInsertCmChargeTable(t *testing.T) {
  45. convey.Convey("InsertCmChargeTable", t, func(ctx convey.C) {
  46. var (
  47. c = context.Background()
  48. vals = "(1,2,3,100,'2018-06-24','2018-06-24')"
  49. table = "column_monthly_charge"
  50. )
  51. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  52. rows, err := d.InsertCmChargeTable(c, vals, table)
  53. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  54. ctx.So(err, convey.ShouldBeNil)
  55. ctx.So(rows, convey.ShouldNotBeNil)
  56. })
  57. })
  58. })
  59. }
  60. func TestChargeInsertCmStatisBatch(t *testing.T) {
  61. convey.Convey("InsertCmStatisBatch", t, func(ctx convey.C) {
  62. var (
  63. c = context.Background()
  64. vals = "(1,2,3,4,'2018-06-24')"
  65. )
  66. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  67. rows, err := d.InsertCmStatisBatch(c, vals)
  68. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldBeNil)
  70. ctx.So(rows, convey.ShouldNotBeNil)
  71. })
  72. })
  73. })
  74. }