memcache_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/smartystreets/goconvey/convey"
  6. )
  7. func TestDaocouponBalancesKey(t *testing.T) {
  8. convey.Convey("couponBalancesKey", t, func(convCtx convey.C) {
  9. var (
  10. mid = int64(1)
  11. ct = int8(2)
  12. )
  13. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  14. p1 := couponBalancesKey(mid, ct)
  15. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  16. convCtx.So(p1, convey.ShouldEqual, "cbl:2:1")
  17. })
  18. })
  19. })
  20. }
  21. func TestDaoDelCouponBalancesCache(t *testing.T) {
  22. convey.Convey("DelCouponBalancesCache", t, func(convCtx convey.C) {
  23. var (
  24. c = context.Background()
  25. mid = int64(0)
  26. ct = int8(0)
  27. )
  28. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  29. err := d.DelCouponBalancesCache(c, mid, ct)
  30. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  31. convCtx.So(err, convey.ShouldBeNil)
  32. })
  33. })
  34. })
  35. }
  36. func TestDaocouponsKey(t *testing.T) {
  37. convey.Convey("couponsKey", t, func(convCtx convey.C) {
  38. var (
  39. mid = int64(22)
  40. ct = int8(33)
  41. )
  42. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  43. p1 := couponsKey(mid, ct)
  44. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  45. convCtx.So(p1, convey.ShouldEqual, "cs:33:22")
  46. })
  47. })
  48. })
  49. }
  50. func TestDaoprizeCardKey(t *testing.T) {
  51. convey.Convey("prizeCardKey", t, func(convCtx convey.C) {
  52. var (
  53. mid = int64(22)
  54. actID = int64(1)
  55. cardType = int8(0)
  56. )
  57. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  58. p1 := prizeCardKey(mid, actID, cardType)
  59. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  60. convCtx.So(p1, convey.ShouldEqual, "nypc:22:1:0")
  61. })
  62. })
  63. })
  64. }
  65. func TestDaoprizeCardsKey(t *testing.T) {
  66. convey.Convey("prizeCardsKey", t, func(convCtx convey.C) {
  67. var (
  68. mid = int64(33)
  69. actID = int64(1)
  70. )
  71. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  72. p1 := prizeCardsKey(mid, actID)
  73. convCtx.Convey("Then p1 should not be nil.", func(convCtx convey.C) {
  74. convCtx.So(p1, convey.ShouldEqual, "nypcs:33:1")
  75. })
  76. })
  77. })
  78. }
  79. func TestDaoDelCouponsCache(t *testing.T) {
  80. convey.Convey("DelCouponsCache", t, func(convCtx convey.C) {
  81. var (
  82. c = context.Background()
  83. mid = int64(1)
  84. ct = int8(1)
  85. )
  86. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  87. err := d.DelCouponsCache(c, mid, ct)
  88. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  89. convCtx.So(err, convey.ShouldBeNil)
  90. })
  91. })
  92. })
  93. }
  94. func TestDaodelCache(t *testing.T) {
  95. convey.Convey("delCache", t, func(convCtx convey.C) {
  96. var (
  97. c = context.Background()
  98. key = "1"
  99. )
  100. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  101. err := d.delCache(c, key)
  102. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  103. convCtx.So(err, convey.ShouldBeNil)
  104. })
  105. err = d.delCache(c, "")
  106. convCtx.Convey("Then err should be not nil.", func(convCtx convey.C) {
  107. convCtx.So(err, convey.ShouldNotBeNil)
  108. })
  109. })
  110. })
  111. }
  112. func TestDaoDelPrizeCardKey(t *testing.T) {
  113. convey.Convey("DelPrizeCardKey", t, func(convCtx convey.C) {
  114. var (
  115. c = context.Background()
  116. mid = int64(0)
  117. actID = int64(0)
  118. cardType = int8(0)
  119. )
  120. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  121. err := d.DelPrizeCardKey(c, mid, actID, cardType)
  122. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  123. convCtx.So(err, convey.ShouldBeNil)
  124. })
  125. })
  126. })
  127. }
  128. func TestDaoDelPrizeCardsKey(t *testing.T) {
  129. convey.Convey("DelPrizeCardsKey", t, func(convCtx convey.C) {
  130. var (
  131. c = context.Background()
  132. mid = int64(0)
  133. actID = int64(0)
  134. )
  135. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  136. err := d.DelPrizeCardsKey(c, mid, actID)
  137. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  138. convCtx.So(err, convey.ShouldBeNil)
  139. })
  140. })
  141. })
  142. }