user_likes_redis_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/job/main/thumbup/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaouserLikesKey(t *testing.T) {
  9. convey.Convey("userLikesKey", t, func(convCtx convey.C) {
  10. var (
  11. businessID = int64(33)
  12. mid = int64(2233)
  13. state = int8(1)
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. p1 := userLikesKey(businessID, mid, state)
  17. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(p1, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoExpireUserLikesCache(t *testing.T) {
  24. convey.Convey("ExpireUserLikesCache", t, func(convCtx convey.C) {
  25. var (
  26. c = context.Background()
  27. mid = int64(0)
  28. businessID = int64(0)
  29. state = int8(0)
  30. )
  31. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  32. ok, err := d.ExpireUserLikesCache(c, mid, businessID, state)
  33. convCtx.Convey("Then err should be nil.ok should not be nil.", func(convCtx convey.C) {
  34. convCtx.So(err, convey.ShouldBeNil)
  35. convCtx.So(ok, convey.ShouldNotBeNil)
  36. })
  37. })
  38. })
  39. }
  40. func TestDaoAppendCacheUserLikeList(t *testing.T) {
  41. convey.Convey("AppendCacheUserLikeList", t, func(convCtx convey.C) {
  42. var (
  43. c = context.Background()
  44. mid = int64(0)
  45. item = &model.ItemLikeRecord{}
  46. businessID = int64(0)
  47. state = int8(0)
  48. limit = int(0)
  49. )
  50. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  51. err := d.AppendCacheUserLikeList(c, mid, item, businessID, state, limit)
  52. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  53. convCtx.So(err, convey.ShouldBeNil)
  54. })
  55. })
  56. })
  57. }
  58. func TestDaoAddUserLikesCache(t *testing.T) {
  59. convey.Convey("AddUserLikesCache", t, func(convCtx convey.C) {
  60. var (
  61. c = context.Background()
  62. mid = int64(0)
  63. businessID = int64(0)
  64. items = []*model.ItemLikeRecord{}
  65. typ = int8(0)
  66. limit = int(0)
  67. )
  68. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  69. err := d.AddUserLikesCache(c, mid, businessID, items, typ, limit)
  70. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  71. convCtx.So(err, convey.ShouldBeNil)
  72. })
  73. })
  74. })
  75. }
  76. func TestDaoDelUserLikeCache(t *testing.T) {
  77. convey.Convey("DelUserLikeCache", t, func(convCtx convey.C) {
  78. var (
  79. c = context.Background()
  80. mid = int64(0)
  81. businessID = int64(0)
  82. messageID = int64(0)
  83. state = int8(0)
  84. )
  85. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  86. err := d.DelUserLikeCache(c, mid, businessID, messageID, state)
  87. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  88. convCtx.So(err, convey.ShouldBeNil)
  89. })
  90. })
  91. })
  92. }