redis_test.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaohashField(t *testing.T) {
  8. var (
  9. aid = int64(1)
  10. tp = int64(1)
  11. )
  12. convey.Convey("hashField", t, func(ctx convey.C) {
  13. p1 := hashField(aid, tp)
  14. ctx.Convey("p1 should not be nil", func(ctx convey.C) {
  15. ctx.So(p1, convey.ShouldNotBeNil)
  16. })
  17. })
  18. }
  19. func TestDaoaddKey2(t *testing.T) {
  20. var (
  21. mid = int64(123)
  22. )
  23. convey.Convey("addKey2", t, func(ctx convey.C) {
  24. key := addKey2(mid)
  25. ctx.Convey("key should not be nil", func(ctx convey.C) {
  26. ctx.So(key, convey.ShouldNotBeNil)
  27. })
  28. })
  29. }
  30. func TestDaoCoinsAddedCache(t *testing.T) {
  31. var (
  32. c = context.TODO()
  33. mid = int64(123)
  34. aid = int64(1)
  35. tp = int64(60)
  36. )
  37. convey.Convey("CoinsAddedCache", t, func(ctx convey.C) {
  38. added, err := d.CoinsAddedCache(c, mid, aid, tp)
  39. ctx.Convey("Error should be nil", func(ctx convey.C) {
  40. ctx.So(err, convey.ShouldBeNil)
  41. })
  42. ctx.Convey("added should not be nil", func(ctx convey.C) {
  43. ctx.So(added, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func TestDaoSetCoinAddedCache(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. mid = int64(123)
  51. aid = int64(1)
  52. tp = int64(60)
  53. count = int64(20)
  54. )
  55. convey.Convey("SetCoinAddedCache", t, func(ctx convey.C) {
  56. err := d.SetCoinAddedCache(c, mid, aid, tp, count)
  57. ctx.Convey("Error should be nil", func(ctx convey.C) {
  58. ctx.So(err, convey.ShouldBeNil)
  59. })
  60. })
  61. }
  62. func TestDaoSetCoinAddedsCache(t *testing.T) {
  63. var (
  64. c = context.TODO()
  65. mid = int64(123)
  66. counts = map[int64]int64{10: 20, 20: 30, 30: 40}
  67. )
  68. convey.Convey("SetCoinAddedsCache", t, func(ctx convey.C) {
  69. err := d.SetCoinAddedsCache(c, mid, counts)
  70. ctx.Convey("Error should be nil", func(ctx convey.C) {
  71. ctx.So(err, convey.ShouldBeNil)
  72. })
  73. })
  74. }
  75. func TestDaoIncrCoinAddedCache(t *testing.T) {
  76. var (
  77. c = context.TODO()
  78. mid = int64(123)
  79. aid = int64(1)
  80. tp = int64(60)
  81. count = int64(20)
  82. )
  83. convey.Convey("IncrCoinAddedCache", t, func(ctx convey.C) {
  84. err := d.IncrCoinAddedCache(c, mid, aid, tp, count)
  85. ctx.Convey("Error should be nil", func(ctx convey.C) {
  86. ctx.So(err, convey.ShouldBeNil)
  87. })
  88. })
  89. }
  90. func TestDaoExpireCoinAdded(t *testing.T) {
  91. var (
  92. c = context.TODO()
  93. mid = int64(123)
  94. )
  95. convey.Convey("ExpireCoinAdded", t, func(ctx convey.C) {
  96. ok, err := d.ExpireCoinAdded(c, mid)
  97. ctx.Convey("Error should be nil", func(ctx convey.C) {
  98. ctx.So(err, convey.ShouldBeNil)
  99. })
  100. ctx.Convey("ok should not be nil", func(ctx convey.C) {
  101. ctx.So(ok, convey.ShouldNotBeNil)
  102. })
  103. })
  104. }