localcache_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package dao
  2. import (
  3. "testing"
  4. "time"
  5. "go-common/app/service/main/ugcpay-rank/internal/conf"
  6. "go-common/app/service/main/ugcpay-rank/internal/model"
  7. xtime "go-common/library/time"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestDaoLCLoadElecAVRankFromNil(t *testing.T) {
  11. convey.Convey("loadElecAVRank", t, func(ctx convey.C) {
  12. var (
  13. avID = int64(233)
  14. ver = int64(0)
  15. )
  16. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  17. rank, err := d.LCLoadElecAVRank(avID, ver)
  18. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  19. ctx.So(err, convey.ShouldBeNil)
  20. ctx.So(rank, convey.ShouldBeNil)
  21. })
  22. })
  23. })
  24. }
  25. func TestDaoLCStoreElecAVRank(t *testing.T) {
  26. convey.Convey("storeElecAVRank", t, func(ctx convey.C) {
  27. var (
  28. avID = int64(233)
  29. ver = int64(0)
  30. rank = &model.RankElecAVProto{
  31. AVID: 233,
  32. }
  33. )
  34. conf.Conf.LocalCache.ElecAVRankTTL = xtime.Duration(time.Second)
  35. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  36. err := d.LCStoreElecAVRank(avID, ver, rank)
  37. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  38. ctx.So(err, convey.ShouldBeNil)
  39. })
  40. })
  41. })
  42. }
  43. func TestDaoLCLoadElecAVRank(t *testing.T) {
  44. convey.Convey("loadElecAVRank", t, func(ctx convey.C) {
  45. var (
  46. avID = int64(233)
  47. ver = int64(0)
  48. )
  49. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  50. rank, err := d.LCLoadElecAVRank(avID, ver)
  51. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  52. ctx.So(err, convey.ShouldBeNil)
  53. ctx.So(rank, convey.ShouldNotBeNil)
  54. ctx.So(rank.AVID, convey.ShouldEqual, avID)
  55. })
  56. })
  57. })
  58. }
  59. func TestDaoLCLoadElecAVRankAfterTTL(t *testing.T) {
  60. convey.Convey("loadElecAVRankAfterTTL", t, func(ctx convey.C) {
  61. var (
  62. avID = int64(233)
  63. ver = int64(0)
  64. )
  65. <-time.After(time.Duration(conf.Conf.LocalCache.ElecAVRankTTL))
  66. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  67. rank, err := d.LCLoadElecAVRank(avID, ver)
  68. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  69. ctx.So(err, convey.ShouldBeNil)
  70. ctx.So(rank, convey.ShouldBeNil)
  71. })
  72. })
  73. })
  74. }
  75. func TestDaoLCLoadElecUPRankFromNil(t *testing.T) {
  76. convey.Convey("loadElecUPRank", t, func(ctx convey.C) {
  77. var (
  78. upMID = int64(4633)
  79. ver = int64(0)
  80. )
  81. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  82. rank, err := d.LCLoadElecUPRank(upMID, ver)
  83. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  84. ctx.So(err, convey.ShouldBeNil)
  85. ctx.So(rank, convey.ShouldBeNil)
  86. })
  87. })
  88. })
  89. }
  90. func TestDaoLCStoreElecUPRank(t *testing.T) {
  91. convey.Convey("storeElecUPRank", t, func(ctx convey.C) {
  92. var (
  93. upMID = int64(4633)
  94. ver = int64(0)
  95. rank = &model.RankElecUPProto{
  96. Count: 100,
  97. }
  98. )
  99. conf.Conf.LocalCache.ElecUPRankTTL = xtime.Duration(time.Second)
  100. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  101. err := d.LCStoreElecUPRank(upMID, ver, rank)
  102. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  103. ctx.So(err, convey.ShouldBeNil)
  104. })
  105. })
  106. })
  107. }
  108. func TestDaoLCLoadElecUPRank(t *testing.T) {
  109. convey.Convey("loadElecUPRank", t, func(ctx convey.C) {
  110. var (
  111. upMID = int64(4633)
  112. ver = int64(0)
  113. )
  114. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  115. rank, err := d.LCLoadElecUPRank(upMID, ver)
  116. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  117. ctx.So(err, convey.ShouldBeNil)
  118. ctx.So(rank, convey.ShouldNotBeNil)
  119. ctx.So(rank.Count, convey.ShouldEqual, 100)
  120. })
  121. })
  122. })
  123. }
  124. func TestDaoLCLoadElecUPRankAfterTTL(t *testing.T) {
  125. convey.Convey("loadElecUPRankAfterTTL", t, func(ctx convey.C) {
  126. var (
  127. upMID = int64(4633)
  128. ver = int64(0)
  129. )
  130. <-time.After(time.Duration(conf.Conf.LocalCache.ElecUPRankTTL))
  131. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  132. rank, err := d.LCLoadElecUPRank(upMID, ver)
  133. ctx.Convey("Then err should be nil.rank should not be nil.", func(ctx convey.C) {
  134. ctx.So(err, convey.ShouldBeNil)
  135. ctx.So(rank, convey.ShouldBeNil)
  136. })
  137. })
  138. })
  139. }