redis_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package like
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestLikeredisKey(t *testing.T) {
  8. convey.Convey("redisKey", t, func(ctx convey.C) {
  9. var (
  10. key = "1"
  11. )
  12. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  13. p1 := redisKey(key)
  14. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. })
  19. }
  20. func TestLikeRsSet(t *testing.T) {
  21. convey.Convey("RsSet", t, func(ctx convey.C) {
  22. var (
  23. c = context.Background()
  24. key = "111"
  25. value = "1"
  26. )
  27. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  28. err := d.RsSet(c, key, value)
  29. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  30. ctx.So(err, convey.ShouldBeNil)
  31. })
  32. })
  33. })
  34. }
  35. func TestLikeRbSet(t *testing.T) {
  36. convey.Convey("RbSet", t, func(ctx convey.C) {
  37. var (
  38. c = context.Background()
  39. key = "111"
  40. value = []byte("1")
  41. )
  42. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  43. err := d.RbSet(c, key, value)
  44. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  45. ctx.So(err, convey.ShouldBeNil)
  46. })
  47. })
  48. })
  49. }
  50. func TestLikeRsGet(t *testing.T) {
  51. convey.Convey("RsGet", t, func(ctx convey.C) {
  52. var (
  53. c = context.Background()
  54. key = "1"
  55. )
  56. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  57. res, err := d.RsGet(c, key)
  58. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. ctx.So(res, convey.ShouldNotBeNil)
  61. })
  62. })
  63. })
  64. }
  65. func TestLikeRsSetNX(t *testing.T) {
  66. convey.Convey("RsSetNX", t, func(ctx convey.C) {
  67. var (
  68. c = context.Background()
  69. key = "2"
  70. )
  71. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  72. res, err := d.RsSetNX(c, key)
  73. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  74. ctx.So(err, convey.ShouldBeNil)
  75. ctx.So(res, convey.ShouldNotBeNil)
  76. })
  77. })
  78. })
  79. }
  80. func TestLikeIncr(t *testing.T) {
  81. convey.Convey("Incr", t, func(ctx convey.C) {
  82. var (
  83. c = context.Background()
  84. key = "1"
  85. )
  86. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  87. res, err := d.Incr(c, key)
  88. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  89. ctx.So(err, convey.ShouldBeNil)
  90. ctx.So(res, convey.ShouldNotBeNil)
  91. })
  92. })
  93. })
  94. }
  95. func TestLikeCreateSelection(t *testing.T) {
  96. convey.Convey("CreateSelection", t, func(ctx convey.C) {
  97. var (
  98. c = context.Background()
  99. aid = int64(1)
  100. stage = int64(1)
  101. )
  102. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  103. err := d.CreateSelection(c, aid, stage)
  104. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  105. ctx.So(err, convey.ShouldBeNil)
  106. })
  107. })
  108. })
  109. }
  110. func TestLikeSelection(t *testing.T) {
  111. convey.Convey("Selection", t, func(ctx convey.C) {
  112. var (
  113. c = context.Background()
  114. aid = int64(1)
  115. stage = int64(1)
  116. )
  117. ctx.Convey("When everything gose positive", func(ctx convey.C) {
  118. yes, no, err := d.Selection(c, aid, stage)
  119. ctx.Convey("Then err should be nil.yes,no should not be nil.", func(ctx convey.C) {
  120. ctx.So(err, convey.ShouldBeNil)
  121. ctx.So(no, convey.ShouldNotBeNil)
  122. ctx.So(yes, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }