redis_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/interface/main/space/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaokeyUpArt(t *testing.T) {
  9. convey.Convey("keyUpArt", t, func(ctx convey.C) {
  10. var (
  11. mid = int64(0)
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1 := keyUpArt(mid)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. })
  20. }
  21. func TestDaokeyUpArc(t *testing.T) {
  22. convey.Convey("keyUpArc", t, func(ctx convey.C) {
  23. var (
  24. mid = int64(0)
  25. )
  26. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  27. p1 := keyUpArc(mid)
  28. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. })
  33. }
  34. func TestDaoSetUpArtCache(t *testing.T) {
  35. convey.Convey("SetUpArtCache", t, func(ctx convey.C) {
  36. var (
  37. c = context.Background()
  38. mid = int64(2222)
  39. data = &model.UpArtStat{View: 2222, Reply: 2222}
  40. )
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. err := d.SetUpArtCache(c, mid, data)
  43. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. })
  46. })
  47. })
  48. }
  49. func TestDaoUpArtCache(t *testing.T) {
  50. convey.Convey("UpArtCache", t, func(ctx convey.C) {
  51. var (
  52. c = context.Background()
  53. mid = int64(2222)
  54. )
  55. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  56. data, err := d.UpArtCache(c, mid)
  57. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. ctx.So(data, convey.ShouldNotBeNil)
  60. })
  61. })
  62. })
  63. }
  64. func TestDaoSetUpArcCache(t *testing.T) {
  65. convey.Convey("SetUpArcCache", t, func(ctx convey.C) {
  66. var (
  67. c = context.Background()
  68. mid = int64(2222)
  69. data = &model.UpArcStat{View: 2222, Reply: 2222}
  70. )
  71. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  72. err := d.SetUpArcCache(c, mid, data)
  73. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  74. ctx.So(err, convey.ShouldBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestDaoUpArcCache(t *testing.T) {
  80. convey.Convey("UpArcCache", t, func(ctx convey.C) {
  81. var (
  82. c = context.Background()
  83. mid = int64(2222)
  84. )
  85. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  86. data, err := d.UpArcCache(c, mid)
  87. ctx.Convey("Then err should be nil.data should not be nil.", func(ctx convey.C) {
  88. ctx.So(err, convey.ShouldBeNil)
  89. ctx.So(data, convey.ShouldNotBeNil)
  90. })
  91. })
  92. })
  93. }
  94. func TestDaosetKvCache(t *testing.T) {
  95. convey.Convey("setKvCache", t, func(ctx convey.C) {
  96. var (
  97. conn = d.redis.Get(context.Background())
  98. key = ""
  99. value = []byte("")
  100. expire = int32(0)
  101. )
  102. defer conn.Close()
  103. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  104. err := setKvCache(conn, key, value, expire)
  105. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  106. ctx.So(err, convey.ShouldBeNil)
  107. })
  108. })
  109. })
  110. }