redis_test.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoSetList(t *testing.T) {
  9. convey.Convey("SetList", t, func(ctx convey.C) {
  10. var (
  11. c = context.Background()
  12. key = "test_list"
  13. ids = []int64{1}
  14. )
  15. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  16. err := d.SetList(c, key, ids)
  17. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  18. ctx.So(err, convey.ShouldBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestDaoExistKey(t *testing.T) {
  24. convey.Convey("ExistKey", t, func(ctx convey.C) {
  25. var (
  26. c = context.Background()
  27. key = ""
  28. )
  29. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  30. exist, err := d.ExistKey(c, key)
  31. ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(exist, convey.ShouldNotBeNil)
  34. })
  35. })
  36. })
  37. }
  38. func TestDaoSetString(t *testing.T) {
  39. convey.Convey("SetString", t, func(ctx convey.C) {
  40. var (
  41. c = context.Background()
  42. key = ""
  43. val = ""
  44. )
  45. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  46. err := d.SetString(c, key, val)
  47. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  48. ctx.So(err, convey.ShouldBeNil)
  49. })
  50. })
  51. })
  52. }
  53. func TestDaoSetCrash(t *testing.T) {
  54. convey.Convey("SetCrash", t, func(ctx convey.C) {
  55. var (
  56. c = context.Background()
  57. )
  58. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  59. err := d.SetCrash(c)
  60. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  61. ctx.So(err, convey.ShouldBeNil)
  62. })
  63. })
  64. })
  65. }
  66. func TestDaoIsCrash(t *testing.T) {
  67. convey.Convey("IsCrash", t, func(ctx convey.C) {
  68. var (
  69. c = context.Background()
  70. )
  71. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  72. exist, err := d.IsCrash(c)
  73. ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
  74. ctx.So(err, convey.ShouldBeNil)
  75. ctx.So(exist, convey.ShouldNotBeNil)
  76. })
  77. })
  78. })
  79. }
  80. func TestDaoUperInfoCache(t *testing.T) {
  81. convey.Convey("UpInfoCache", t, func(ctx convey.C) {
  82. var (
  83. c = context.Background()
  84. mids = []int64{0}
  85. )
  86. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  87. groups, err := d.UperInfoCache(c, mids)
  88. ctx.Convey("Then err should be nil.groups should not be nil.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldBeNil)
  90. ctx.So(groups, convey.ShouldNotBeNil)
  91. fmt.Println("len groups", len(groups), groups)
  92. })
  93. })
  94. })
  95. }
  96. func TestDaoSetWeightSortedSet(t *testing.T) {
  97. convey.Convey("SetWeightSortedSet", t, func(ctx convey.C) {
  98. var (
  99. c = context.Background()
  100. newWeigt = map[int64]int64{1: 200, 2: 1, 3: 10}
  101. )
  102. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  103. err := d.SetWeightSortedSet(c, 1, newWeigt)
  104. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestDaoKeysSingleExpire(t *testing.T) {
  111. convey.Convey("KeysSingleExpire", t, func(ctx convey.C) {
  112. var (
  113. c = context.Background()
  114. )
  115. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  116. _, err := d.SingleExpire(c, 1)
  117. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  118. ctx.So(err, convey.ShouldBeNil)
  119. })
  120. })
  121. })
  122. }