memcache_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "time"
  6. "go-common/app/interface/main/answer/model"
  7. "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestAnswerQidListKey(t *testing.T) {
  10. convey.Convey("answerQidListKey", t, func() {
  11. key := answerQidListKey(7593623, model.BaseExtraPassQ)
  12. convey.So(key, convey.ShouldNotBeNil)
  13. })
  14. }
  15. func TestDaopingMC(t *testing.T) {
  16. convey.Convey("pingMC", t, func() {
  17. err := d.pingMC(context.Background())
  18. convey.So(err, convey.ShouldBeNil)
  19. })
  20. }
  21. func TestDaoSetExpireCache(t *testing.T) {
  22. at := &model.AnswerTime{Etimes: 1}
  23. convey.Convey("SetExpireCache", t, func() {
  24. err := d.SetExpireCache(context.Background(), mid, at)
  25. convey.So(err, convey.ShouldBeNil)
  26. })
  27. convey.Convey("ExpireCache", t, func() {
  28. at, err := d.ExpireCache(context.Background(), mid)
  29. convey.So(err, convey.ShouldBeNil)
  30. convey.So(at, convey.ShouldNotBeNil)
  31. })
  32. }
  33. func TestDaoDelExpireCache(t *testing.T) {
  34. convey.Convey("DelExpireCache", t, func() {
  35. err := d.DelExpireCache(context.Background(), 0)
  36. convey.So(err, convey.ShouldBeNil)
  37. })
  38. }
  39. func TestDaoSetHistoryCache(t *testing.T) {
  40. his := &model.AnswerHistory{Hid: time.Now().Unix()}
  41. convey.Convey("SetHistoryCache", t, func() {
  42. err := d.SetHistoryCache(context.Background(), mid, his)
  43. convey.So(err, convey.ShouldBeNil)
  44. })
  45. convey.Convey("HistoryCache", t, func() {
  46. ah, err := d.HistoryCache(context.Background(), mid)
  47. convey.So(err, convey.ShouldBeNil)
  48. convey.So(ah, convey.ShouldNotBeNil)
  49. })
  50. }
  51. func TestDaoSetIdsCache(t *testing.T) {
  52. convey.Convey("SetIdsCache", t, func() {
  53. err := d.SetIdsCache(context.Background(), mid, []int64{1, 2, 3}, 0)
  54. convey.So(err, convey.ShouldBeNil)
  55. })
  56. convey.Convey("IdsCache", t, func() {
  57. ids, err := d.IdsCache(context.Background(), mid, 0)
  58. convey.So(err, convey.ShouldBeNil)
  59. convey.So(ids, convey.ShouldNotBeNil)
  60. })
  61. convey.Convey("DelHistoryCache", t, func() {
  62. err := d.DelHistoryCache(context.Background(), mid)
  63. convey.So(err, convey.ShouldBeNil)
  64. })
  65. }
  66. func TestDaoDelIdsCache(t *testing.T) {
  67. convey.Convey("DelIdsCache", t, func() {
  68. err := d.DelIdsCache(context.Background(), 0, 0)
  69. convey.So(err, convey.ShouldBeNil)
  70. })
  71. }
  72. func TestDaoSetBlockCache(t *testing.T) {
  73. convey.Convey("SetBlockCache", t, func() {
  74. err := d.SetBlockCache(context.Background(), 0)
  75. convey.So(err, convey.ShouldBeNil)
  76. })
  77. }
  78. func TestDaoCheckBlockCache(t *testing.T) {
  79. convey.Convey("CheckBlockCache", t, func() {
  80. exist, err := d.CheckBlockCache(context.Background(), 0)
  81. convey.So(err, convey.ShouldBeNil)
  82. convey.So(exist, convey.ShouldNotBeNil)
  83. })
  84. }
  85. func TestDaoHidCache(t *testing.T) {
  86. hid := time.Now().Unix()
  87. his := &model.AnswerHistory{Hid: hid}
  88. convey.Convey("SetHidCache", t, func() {
  89. err := d.SetHidCache(context.Background(), his)
  90. convey.So(err, convey.ShouldBeNil)
  91. })
  92. convey.Convey("HidCache", t, func() {
  93. ah, err := d.HidCache(context.Background(), hid)
  94. convey.So(err, convey.ShouldBeNil)
  95. convey.So(ah, convey.ShouldNotBeNil)
  96. })
  97. }