redis_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaokeyWaitBlock(t *testing.T) {
  8. convey.Convey("keyWaitBlock", t, func(ctx convey.C) {
  9. var (
  10. batchNo = int64(0)
  11. )
  12. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  13. p1 := keyWaitBlock(batchNo)
  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 TestDaolockKey(t *testing.T) {
  21. convey.Convey("lockKey", t, func(ctx convey.C) {
  22. var (
  23. key = int64(0)
  24. )
  25. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  26. p1 := lockKey(key)
  27. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  28. ctx.So(p1, convey.ShouldNotBeNil)
  29. })
  30. })
  31. })
  32. }
  33. func TestDaoAddBlockCache(t *testing.T) {
  34. convey.Convey("AddBlockCache", t, func(ctx convey.C) {
  35. var (
  36. c = context.Background()
  37. mid = int64(0)
  38. score = int8(0)
  39. blockNo = int64(0)
  40. )
  41. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  42. err := d.AddBlockCache(c, mid, score, blockNo)
  43. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  44. ctx.So(err, convey.ShouldBeNil)
  45. })
  46. })
  47. })
  48. }
  49. func TestDaoBlockMidCache(t *testing.T) {
  50. convey.Convey("BlockMidCache", t, func(ctx convey.C) {
  51. var (
  52. c = context.Background()
  53. batchNo = int64(0)
  54. num = int64(0)
  55. )
  56. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  57. _, err := d.BlockMidCache(c, batchNo, num)
  58. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. })
  61. })
  62. })
  63. }
  64. func TestDaoSetNXLockCache(t *testing.T) {
  65. convey.Convey("SetNXLockCache", t, func(ctx convey.C) {
  66. var (
  67. c = context.Background()
  68. k = int64(0)
  69. )
  70. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  71. res, err := d.SetNXLockCache(c, k)
  72. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  73. ctx.So(err, convey.ShouldBeNil)
  74. ctx.So(res, convey.ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }
  79. func TestDaoPingRedis(t *testing.T) {
  80. convey.Convey("PingRedis", t, func(ctx convey.C) {
  81. var (
  82. c = context.Background()
  83. )
  84. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  85. err := d.PingRedis(c)
  86. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  87. ctx.So(err, convey.ShouldBeNil)
  88. })
  89. })
  90. })
  91. }