item_likes_redis_test.go 3.6 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 TestDaoitemLikesKey(t *testing.T) {
  9. var (
  10. businessID = int64(1)
  11. messageID = int64(1)
  12. state = int8(1)
  13. )
  14. convey.Convey("itemLikesKey", t, func(ctx convey.C) {
  15. p1 := itemLikesKey(businessID, messageID, 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 TestDaoCacheItemLikeList(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. messageID = int64(1)
  25. businessID = int64(1)
  26. state = int8(1)
  27. start = int(1)
  28. end = int(1)
  29. )
  30. convey.Convey("CacheItemLikeList", t, func(ctx convey.C) {
  31. _, err := d.CacheItemLikeList(c, messageID, 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 TestDaoAddCacheItemLikeList(t *testing.T) {
  39. var (
  40. c = context.TODO()
  41. messageID = int64(1)
  42. miss = []*model.UserLikeRecord{}
  43. businessID = int64(1)
  44. state = int8(1)
  45. )
  46. convey.Convey("AddCacheItemLikeList", t, func(ctx convey.C) {
  47. err := d.AddCacheItemLikeList(c, messageID, 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 TestDaoExpireItemLikesCache(t *testing.T) {
  54. var (
  55. c = context.TODO()
  56. messageID = int64(1)
  57. businessID = int64(1)
  58. state = int8(1)
  59. )
  60. convey.Convey("ExpireItemLikesCache", t, func(ctx convey.C) {
  61. ok, err := d.ExpireItemLikesCache(c, messageID, 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 TestDaoItemLikeExists(t *testing.T) {
  69. var (
  70. c = context.TODO()
  71. messageID = int64(1)
  72. businessID = int64(1)
  73. mids = []int64{}
  74. state = int8(1)
  75. )
  76. convey.Convey("ItemLikeExists", t, func(ctx convey.C) {
  77. res, err := d.ItemLikeExists(c, messageID, businessID, mids, 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 TestDaoAppendCacheItemLikeList(t *testing.T) {
  85. var (
  86. c = context.TODO()
  87. messageID = int64(1)
  88. item = &model.UserLikeRecord{}
  89. businessID = int64(1)
  90. state = int8(1)
  91. )
  92. convey.Convey("AppendCacheItemLikeList", t, func(ctx convey.C) {
  93. err := d.AppendCacheItemLikeList(c, messageID, 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 TestDaoDelItemLikeCache(t *testing.T) {
  100. var (
  101. c = context.TODO()
  102. messageID = int64(1)
  103. businessID = int64(1)
  104. mid = int64(1)
  105. state = int8(1)
  106. )
  107. convey.Convey("DelItemLikeCache", t, func(ctx convey.C) {
  108. err := d.DelItemLikeCache(c, messageID, businessID, mid, state)
  109. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  110. ctx.So(err, convey.ShouldBeNil)
  111. })
  112. })
  113. }
  114. func TestDaoItemLikesCountCache(t *testing.T) {
  115. var (
  116. c = context.TODO()
  117. businessID = int64(1)
  118. messageID = int64(1)
  119. )
  120. convey.Convey("ItemLikesCountCache", t, func(ctx convey.C) {
  121. res, err := d.ItemLikesCountCache(c, businessID, messageID)
  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. }