bgm_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package charge
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestChargeGetBgm(t *testing.T) {
  9. convey.Convey("GetBgm", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. id = int64(0)
  13. limit = int64(10)
  14. )
  15. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  16. d.db.Exec(c, "INSERT INTO backgroud_music(aid,sid) VALUES(1,2)")
  17. bs, last, err := d.GetBgm(c, id, limit)
  18. ctx.Convey("Then err should be nil.bs,last should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(last, convey.ShouldNotBeNil)
  21. ctx.So(bs, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestChargeBgmCharge(t *testing.T) {
  27. convey.Convey("BgmCharge", t, func(ctx convey.C) {
  28. var (
  29. c = context.Background()
  30. date = time.Date(2018, 6, 24, 0, 0, 0, 0, time.Local)
  31. id = int64(0)
  32. limit = int(100)
  33. table = "bgm_daily_charge"
  34. )
  35. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  36. d.db.Exec(c, "INSERT INTO bgm_daily_charge(aid,sid,inc_charge) VALUES(1,2,3)")
  37. bgms, err := d.BgmCharge(c, date, id, limit, table)
  38. ctx.Convey("Then err should be nil.bgms should not be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. ctx.So(bgms, convey.ShouldNotBeNil)
  41. })
  42. })
  43. })
  44. }
  45. func TestChargeBgmStatis(t *testing.T) {
  46. convey.Convey("BgmStatis", t, func(ctx convey.C) {
  47. var (
  48. c = context.Background()
  49. id = int64(0)
  50. limit = int(100)
  51. )
  52. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  53. d.db.Exec(c, "INSERT INTO bgm_charge_statis(aid,sid,total_charge) VALUES(1,2,3)")
  54. bgms, err := d.BgmStatis(c, id, limit)
  55. ctx.Convey("Then err should be nil.bgms should not be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(bgms, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. func TestChargeInsertBgmChargeTable(t *testing.T) {
  63. convey.Convey("InsertBgmChargeTable", t, func(ctx convey.C) {
  64. var (
  65. c = context.Background()
  66. vals = "(1,2,3,4,'test',100, '2018-06-24','2018-06-24')"
  67. table = "bgm_weekly_charge"
  68. )
  69. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  70. rows, err := d.InsertBgmChargeTable(c, vals, table)
  71. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  72. ctx.So(err, convey.ShouldBeNil)
  73. ctx.So(rows, convey.ShouldNotBeNil)
  74. })
  75. })
  76. })
  77. }
  78. func TestChargeInsertBgmStatisBatch(t *testing.T) {
  79. convey.Convey("InsertBgmStatisBatch", t, func(ctx convey.C) {
  80. var (
  81. c = context.Background()
  82. vals = "(1,2,3,4,'test',100,'2018-06-24')"
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  85. rows, err := d.InsertBgmStatisBatch(c, vals)
  86. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. ctx.So(rows, convey.ShouldNotBeNil)
  89. })
  90. })
  91. })
  92. }