item_likes_redis_test.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/job/main/thumbup/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoitemLikesKey(t *testing.T) {
  9. convey.Convey("itemLikesKey", t, func(convCtx convey.C) {
  10. var (
  11. businessID = int64(33)
  12. messageID = int64(5566)
  13. state = int8(1)
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. p1 := itemLikesKey(businessID, messageID, 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 TestDaoExpireItemLikesCache(t *testing.T) {
  24. convey.Convey("ExpireItemLikesCache", t, func(convCtx convey.C) {
  25. var (
  26. c = context.Background()
  27. messageID = int64(5566)
  28. businessID = int64(33)
  29. state = int8(1)
  30. )
  31. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  32. ok, err := d.ExpireItemLikesCache(c, messageID, 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 TestDaoAddItemLikesCache(t *testing.T) {
  41. convey.Convey("AddItemLikesCache", t, func(convCtx convey.C) {
  42. var (
  43. c = context.Background()
  44. businessID = int64(33)
  45. messageID = int64(5566)
  46. typ = int8(1)
  47. limit = int(100)
  48. items = []*model.UserLikeRecord{}
  49. )
  50. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  51. err := d.AddItemLikesCache(c, businessID, messageID, typ, limit, items)
  52. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  53. convCtx.So(err, convey.ShouldBeNil)
  54. })
  55. })
  56. })
  57. }
  58. func TestDaoAppendCacheItemLikeList(t *testing.T) {
  59. convey.Convey("AppendCacheItemLikeList", t, func(convCtx convey.C) {
  60. var (
  61. c = context.Background()
  62. messageID = int64(5566)
  63. item = &model.UserLikeRecord{}
  64. businessID = int64(33)
  65. state = int8(1)
  66. limit = int(100)
  67. )
  68. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  69. err := d.AppendCacheItemLikeList(c, messageID, item, businessID, state, 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 TestDaoDelItemLikeCache(t *testing.T) {
  77. convey.Convey("DelItemLikeCache", t, func(convCtx convey.C) {
  78. var (
  79. c = context.Background()
  80. messageID = int64(5566)
  81. businessID = int64(33)
  82. mid = int64(2233)
  83. state = int8(1)
  84. )
  85. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  86. err := d.DelItemLikeCache(c, messageID, businessID, mid, state)
  87. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  88. convCtx.So(err, convey.ShouldBeNil)
  89. })
  90. })
  91. })
  92. }