redis_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. pb "go-common/app/service/main/history/api/grpc"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoListCache(t *testing.T) {
  9. var (
  10. c = context.Background()
  11. business = "pgc"
  12. mid = int64(1)
  13. start = int64(0)
  14. his = []*pb.AddHistoryReq{{
  15. Mid: 1,
  16. Business: "pgc",
  17. Kid: 1,
  18. Aid: 2,
  19. Sid: 3,
  20. },
  21. }
  22. h = &pb.AddHistoryReq{
  23. Mid: 2,
  24. Business: "pgc",
  25. Kid: 1,
  26. Aid: 2,
  27. Sid: 3,
  28. }
  29. )
  30. convey.Convey("add his", t, func() {
  31. convey.So(d.AddHistoriesCache(c, his), convey.ShouldBeNil)
  32. convey.So(d.AddHistoryCache(c, h), convey.ShouldBeNil)
  33. convey.Convey("ListCacheByTime", func(ctx convey.C) {
  34. aids, err := d.ListCacheByTime(c, business, mid, start)
  35. ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx convey.C) {
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(aids, convey.ShouldNotBeEmpty)
  38. })
  39. })
  40. convey.Convey("ListsCacheByTime", func(ctx convey.C) {
  41. var (
  42. c = context.Background()
  43. businesses = []string{"pgc"}
  44. viewAt = int64(100)
  45. ps = int64(1)
  46. )
  47. res, err := d.ListsCacheByTime(c, businesses, mid, viewAt, ps)
  48. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. ctx.So(res, convey.ShouldNotBeNil)
  51. })
  52. })
  53. convey.Convey("HistoriesCache", func(ctx convey.C) {
  54. var hs = map[string][]int64{"pgc": {1}}
  55. res, err := d.HistoriesCache(c, 2, hs)
  56. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  57. ctx.So(err, convey.ShouldBeNil)
  58. ctx.So(res, convey.ShouldNotBeNil)
  59. })
  60. })
  61. convey.Convey("ClearHistoryCache", func(ctx convey.C) {
  62. err := d.ClearHistoryCache(c, mid, []string{business})
  63. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  64. ctx.So(err, convey.ShouldBeNil)
  65. })
  66. })
  67. convey.Convey("DelHistoryCache", func(ctx convey.C) {
  68. ctx.So(d.DelHistoryCache(c, &pb.DelHistoriesReq{
  69. Mid: 1, Records: []*pb.DelHistoriesReq_Record{{ID: 1, Business: "pgc"}},
  70. }), convey.ShouldBeNil)
  71. })
  72. convey.Convey("TrimCache", func(ctx convey.C) {
  73. err := d.TrimCache(c, business, mid, 10)
  74. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  75. ctx.So(err, convey.ShouldBeNil)
  76. })
  77. })
  78. })
  79. }
  80. func TestDaoDelCache(t *testing.T) {
  81. var (
  82. c = context.Background()
  83. business = "pgc"
  84. mid = int64(1)
  85. aids = []int64{1}
  86. )
  87. convey.Convey("DelCache", t, func(ctx convey.C) {
  88. err := d.DelCache(c, business, mid, aids)
  89. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  90. ctx.So(err, convey.ShouldBeNil)
  91. })
  92. })
  93. }
  94. func TestDaoSetUserHideCache(t *testing.T) {
  95. var (
  96. c = context.Background()
  97. mid = int64(1)
  98. value = int64(1)
  99. )
  100. convey.Convey("SetUserHideCache", t, func(ctx convey.C) {
  101. err := d.SetUserHideCache(c, mid, value)
  102. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  103. ctx.So(err, convey.ShouldBeNil)
  104. })
  105. })
  106. }
  107. func TestDaoUserHideCache(t *testing.T) {
  108. var (
  109. c = context.Background()
  110. mid = int64(1)
  111. )
  112. convey.Convey("UserHideCache", t, func(ctx convey.C) {
  113. value, err := d.UserHideCache(c, mid)
  114. ctx.Convey("Then err should be nil.value should not be nil.", func(ctx convey.C) {
  115. ctx.So(err, convey.ShouldBeNil)
  116. ctx.So(value, convey.ShouldNotBeNil)
  117. // ctx.So(value, convey.ShouldEqual, 1)
  118. })
  119. })
  120. }