user_likes_redis_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/thumbup/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaouserLikesKey(t *testing.T) {
  9. var (
  10. businessID = int64(1)
  11. mid = int64(1)
  12. state = int8(1)
  13. )
  14. convey.Convey("userLikesKey", t, func(ctx convey.C) {
  15. p1 := userLikesKey(businessID, mid, state)
  16. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  17. ctx.So(p1, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func TestDaoCacheUserLikeList(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. mid = int64(1)
  25. businessID = int64(1)
  26. state = int8(1)
  27. start = int(1)
  28. end = int(10)
  29. )
  30. convey.Convey("CacheUserLikeList", t, func(ctx convey.C) {
  31. _, err := d.CacheUserLikeList(c, mid, businessID, state, start, end)
  32. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  33. ctx.So(err, convey.ShouldBeNil)
  34. // ctx.So(res, convey.ShouldNotBeNil)
  35. })
  36. })
  37. }
  38. func TestDaoAddCacheUserLikeList(t *testing.T) {
  39. var (
  40. c = context.TODO()
  41. mid = int64(1)
  42. miss = []*model.ItemLikeRecord{}
  43. businessID = int64(1)
  44. state = int8(1)
  45. )
  46. convey.Convey("AddCacheUserLikeList", t, func(ctx convey.C) {
  47. err := d.AddCacheUserLikeList(c, mid, miss, businessID, state)
  48. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  49. ctx.So(err, convey.ShouldBeNil)
  50. })
  51. })
  52. }
  53. func TestDaoExpireUserLikesCache(t *testing.T) {
  54. var (
  55. c = context.TODO()
  56. mid = int64(1)
  57. businessID = int64(1)
  58. state = int8(1)
  59. )
  60. convey.Convey("ExpireUserLikesCache", t, func(ctx convey.C) {
  61. ok, err := d.ExpireUserLikesCache(c, mid, businessID, state)
  62. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  63. ctx.So(err, convey.ShouldBeNil)
  64. ctx.So(ok, convey.ShouldNotBeNil)
  65. })
  66. })
  67. }
  68. func TestDaoUserLikeExists(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. mid = int64(1)
  72. businessID = int64(1)
  73. messageIDs = []int64{}
  74. state = int8(1)
  75. )
  76. convey.Convey("UserLikeExists", t, func(ctx convey.C) {
  77. res, err := d.UserLikeExists(c, mid, businessID, messageIDs, state)
  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 TestDaoAppendCacheUserLikeList(t *testing.T) {
  85. var (
  86. c = context.TODO()
  87. mid = int64(1)
  88. item = &model.ItemLikeRecord{}
  89. businessID = int64(1)
  90. state = int8(1)
  91. )
  92. convey.Convey("AppendCacheUserLikeList", t, func(ctx convey.C) {
  93. err := d.AppendCacheUserLikeList(c, mid, item, businessID, state)
  94. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  95. ctx.So(err, convey.ShouldBeNil)
  96. })
  97. })
  98. }
  99. func TestDaoDelUserLikeCache(t *testing.T) {
  100. var (
  101. c = context.TODO()
  102. mid = int64(1)
  103. businessID = int64(1)
  104. messageID = int64(1)
  105. state = int8(1)
  106. )
  107. convey.Convey("DelUserLikeCache", t, func(ctx convey.C) {
  108. err := d.DelUserLikeCache(c, mid, businessID, messageID, state)
  109. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. }
  114. func TestDaoUserLikesCountCache(t *testing.T) {
  115. var (
  116. c = context.TODO()
  117. businessID = int64(1)
  118. mid = int64(1)
  119. )
  120. convey.Convey("UserLikesCountCache", t, func(ctx convey.C) {
  121. res, err := d.UserLikesCountCache(c, businessID, mid)
  122. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  123. ctx.So(err, convey.ShouldBeNil)
  124. ctx.So(res, convey.ShouldNotBeNil)
  125. })
  126. })
  127. }