stat_redis_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/playlist/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaokeyStat(t *testing.T) {
  9. var (
  10. mid = int64(2)
  11. )
  12. convey.Convey("keyStat", t, func(ctx convey.C) {
  13. p1 := keyStat(mid)
  14. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestDaokeyPl(t *testing.T) {
  20. var (
  21. pid = int64(1)
  22. )
  23. convey.Convey("keyPl", t, func(ctx convey.C) {
  24. p1 := keyPl(pid)
  25. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  26. ctx.So(p1, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDaoPlStatCache(t *testing.T) {
  31. var (
  32. c = context.Background()
  33. mid = int64(2)
  34. pid = int64(1)
  35. )
  36. convey.Convey("PlStatCache", t, func(ctx convey.C) {
  37. _, err := d.PlStatCache(c, mid, pid)
  38. ctx.Convey("Then err should be nil.stat should not be nil.", func(ctx convey.C) {
  39. ctx.So(err, convey.ShouldBeNil)
  40. })
  41. })
  42. }
  43. func TestDaoSetPlStatCache(t *testing.T) {
  44. var (
  45. c = context.Background()
  46. mid = int64(2)
  47. pid = int64(1)
  48. stat = &model.PlStat{}
  49. )
  50. convey.Convey("SetPlStatCache", t, func(ctx convey.C) {
  51. err := d.SetPlStatCache(c, mid, pid, stat)
  52. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  53. ctx.So(err, convey.ShouldBeNil)
  54. })
  55. })
  56. }
  57. func TestDaoSetStatsCache(t *testing.T) {
  58. var (
  59. c = context.Background()
  60. mid = int64(2)
  61. plStats = []*model.PlStat{}
  62. )
  63. plStats = append(plStats, &model.PlStat{ID: 1, Share: 1})
  64. convey.Convey("SetStatsCache", t, func(ctx convey.C) {
  65. err := d.SetStatsCache(c, mid, plStats)
  66. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. }
  71. func TestDaoPlsCache(t *testing.T) {
  72. var (
  73. c = context.Background()
  74. pids = []int64{1, 2, 3}
  75. )
  76. convey.Convey("PlsCache", t, func(ctx convey.C) {
  77. res, err := d.PlsCache(c, pids)
  78. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  79. ctx.So(err, convey.ShouldBeNil)
  80. ctx.So(res, convey.ShouldNotBeNil)
  81. })
  82. })
  83. }
  84. func TestDaoSetPlCache(t *testing.T) {
  85. var (
  86. c = context.Background()
  87. plStats = []*model.PlStat{}
  88. )
  89. plStats = append(plStats, &model.PlStat{ID: 1, View: 100})
  90. convey.Convey("SetPlCache", t, func(ctx convey.C) {
  91. err := d.SetPlCache(c, plStats)
  92. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  93. ctx.So(err, convey.ShouldBeNil)
  94. })
  95. })
  96. }
  97. func TestDaoDelPlCache(t *testing.T) {
  98. var (
  99. c = context.Background()
  100. mid = int64(2)
  101. pid = int64(1)
  102. )
  103. convey.Convey("DelPlCache", t, func(ctx convey.C) {
  104. err := d.DelPlCache(c, mid, pid)
  105. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. })
  108. })
  109. }
  110. func TestDaoStatsCache(t *testing.T) {
  111. var (
  112. c = context.Background()
  113. mid = int64(2)
  114. )
  115. convey.Convey("StatsCache", t, func(ctx convey.C) {
  116. _, err := d.StatsCache(c, mid)
  117. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  118. ctx.So(err, convey.ShouldBeNil)
  119. })
  120. })
  121. }