av_charge_test.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package charge
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestChargeAvDailyCharge(t *testing.T) {
  9. convey.Convey("AvDailyCharge", 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. )
  16. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  17. d.db.Exec(c, "INSERT INTO av_daily_charge_06(av_id,mid,date,inc_charge) VALUES(1,2,'2018-06-24',100) ON DUPLICATE KEY UPDATE inc_charge=VALUES(inc_charge)")
  18. data, err := d.AvDailyCharge(c, date, id, limit)
  19. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  20. ctx.So(err, convey.ShouldBeNil)
  21. ctx.So(data, convey.ShouldNotBeNil)
  22. })
  23. })
  24. })
  25. }
  26. func TestChargeAvWeeklyCharge(t *testing.T) {
  27. convey.Convey("AvWeeklyCharge", 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. )
  34. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  35. d.db.Exec(c, "INSERT INTO av_weekly_charge(av_id,mid,date) VALUES(1,2,'2018-06-24') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  36. data, err := d.AvWeeklyCharge(c, date, id, limit)
  37. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. ctx.So(data, convey.ShouldNotBeNil)
  40. })
  41. })
  42. })
  43. }
  44. func TestChargeAvMonthlyCharge(t *testing.T) {
  45. convey.Convey("AvMonthlyCharge", 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. 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 av_monthly_charge(av_id,mid,date) VALUES(1,2,'2018-06-24') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  54. data, err := d.AvMonthlyCharge(c, date, id, limit)
  55. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  56. ctx.So(err, convey.ShouldBeNil)
  57. ctx.So(data, convey.ShouldNotBeNil)
  58. })
  59. })
  60. })
  61. }
  62. func TestChargeGetAvCharge(t *testing.T) {
  63. convey.Convey("GetAvCharge", t, func(ctx convey.C) {
  64. var (
  65. c = context.Background()
  66. sql = "SELECT id,av_id,mid,tag_id,is_original,upload_time,danmaku_count,comment_count,collect_count,coin_count,share_count,elec_pay_count,total_play_count,web_play_count,app_play_count,h5_play_count,lv_unknown,lv_0,lv_1,lv_2,lv_3,lv_4,lv_5,lv_6,v_score,inc_charge,total_charge,date,is_deleted,ctime,mtime FROM av_monthly_charge WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
  67. date = "2018-06-24"
  68. id = int64(0)
  69. limit = int(100)
  70. )
  71. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  72. d.db.Exec(c, "INSERT INTO av_daily_charge_06(av_id,mid,date) VALUES(1,2,'2018-06-24') ON DUPLICATE KEY UPDATE mid=VALUES(mid)")
  73. data, err := d.GetAvCharge(c, sql, date, id, limit)
  74. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  75. ctx.So(err, convey.ShouldBeNil)
  76. ctx.So(data, convey.ShouldNotBeNil)
  77. })
  78. })
  79. })
  80. }
  81. func TestChargeInsertAvChargeTable(t *testing.T) {
  82. convey.Convey("InsertAvChargeTable", t, func(ctx convey.C) {
  83. var (
  84. c = context.Background()
  85. vals = "(1,2,3,1,5,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,'2018-06-24', '2018-06-24')"
  86. table = "av_weekly_charge"
  87. )
  88. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  89. rows, err := d.InsertAvChargeTable(c, vals, table)
  90. ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
  91. ctx.So(err, convey.ShouldBeNil)
  92. ctx.So(rows, convey.ShouldNotBeNil)
  93. })
  94. })
  95. })
  96. }