redis_test.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. package pendant
  2. import (
  3. "fmt"
  4. "go-common/app/service/main/usersuit/model"
  5. "testing"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestPendantkeyEquip(t *testing.T) {
  9. convey.Convey("keyEquip", t, func(ctx convey.C) {
  10. var (
  11. mid = int64(650454)
  12. )
  13. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  14. p1 := keyEquip(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 TestPendantencode(t *testing.T) {
  22. convey.Convey("encode", t, func(ctx convey.C) {
  23. var (
  24. mid = int64(650454)
  25. pid = int64(1)
  26. expires = int64(1535970125)
  27. tp = int64(0)
  28. status = int32(1)
  29. isVIP = int32(1)
  30. pendant = &model.Pendant{}
  31. )
  32. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  33. res, err := d.encode(mid, pid, expires, tp, status, isVIP, pendant)
  34. ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
  35. fmt.Println(string(res))
  36. ctx.So(err, convey.ShouldBeNil)
  37. ctx.So(res, convey.ShouldNotBeNil)
  38. })
  39. })
  40. })
  41. }
  42. func TestPendantdecode(t *testing.T) {
  43. convey.Convey("decode", t, func(ctx convey.C) {
  44. var (
  45. src = []byte("\u007b\u0022\u0069\u0064\u0022\u003a\u0030\u002c\u0022\u006d\u0069\u0064\u0022\u003a\u0036\u0035\u0030\u0034\u0035\u0034\u002c\u0022\u0070\u0069\u0064\u0022\u003a\u0031\u002c\u0022\u0065\u0078\u0070\u0069\u0072\u0065\u0022\u003a\u0031\u0035\u0033\u0035\u0039\u0037\u0030\u0031\u0032\u0035\u002c\u0022\u0074\u0079\u0070\u0065\u0022\u003a\u0030\u002c\u0022\u0073\u0074\u0061\u0074\u0075\u0073\u0022\u003a\u0031\u002c\u0022\u0069\u0073\u0056\u0049\u0050\u0022\u003a\u0031\u002c\u0022\u0070\u0065\u006e\u0064\u0061\u006e\u0074\u0022\u003a\u007b\u0022\u0070\u0069\u0064\u0022\u003a\u0030\u002c\u0022\u006e\u0061\u006d\u0065\u0022\u003a\u0022\u0022\u002c\u0022\u0069\u006d\u0061\u0067\u0065\u0022\u003a\u0022\u0022\u002c\u0022\u0069\u006d\u0061\u0067\u0065\u005f\u006d\u006f\u0064\u0065\u006c\u0022\u003a\u0022\u0022\u002c\u0022\u0073\u0074\u0061\u0074\u0075\u0073\u0022\u003a\u0030\u002c\u0022\u0063\u006f\u0069\u006e\u0022\u003a\u0030\u002c\u0022\u0070\u006f\u0069\u006e\u0074\u0022\u003a\u0030\u002c\u0022\u0062\u0063\u006f\u0069\u006e\u0022\u003a\u0030\u002c\u0022\u0065\u0078\u0070\u0069\u0072\u0065\u0022\u003a\u0030\u002c\u0022\u0067\u0069\u0064\u0022\u003a\u0030\u002c\u0022\u0072\u0061\u006e\u006b\u0022\u003a\u0030\u007d\u007d")
  46. v = &model.PendantPackage{Mid: 650454, Pid: 1}
  47. )
  48. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  49. err := d.decode(src, v)
  50. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  51. ctx.So(err, convey.ShouldBeNil)
  52. })
  53. })
  54. })
  55. }
  56. func TestPendantAddPKGCache(t *testing.T) {
  57. convey.Convey("AddPKGCache", t, func(ctx convey.C) {
  58. var (
  59. mid = int64(650454)
  60. info = []*model.PendantPackage{}
  61. pp = &model.PendantPackage{Mid: mid, Pid: int64(1)}
  62. )
  63. info = append(info, pp)
  64. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  65. err := d.AddPKGCache(c, mid, info)
  66. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  67. ctx.So(err, convey.ShouldBeNil)
  68. })
  69. })
  70. })
  71. }
  72. func TestPendantPKGCache(t *testing.T) {
  73. convey.Convey("PKGCache", t, func(ctx convey.C) {
  74. var (
  75. mid = int64(650454)
  76. )
  77. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  78. info, err := d.PKGCache(c, mid)
  79. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  80. ctx.So(err, convey.ShouldBeNil)
  81. ctx.So(info, convey.ShouldNotBeNil)
  82. })
  83. })
  84. })
  85. }
  86. func TestPendantDelPKGCache(t *testing.T) {
  87. convey.Convey("DelPKGCache", t, func(ctx convey.C) {
  88. var (
  89. mid = int64(650454)
  90. )
  91. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  92. err := d.DelPKGCache(c, mid)
  93. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  94. ctx.So(err, convey.ShouldBeNil)
  95. })
  96. })
  97. })
  98. }
  99. func TestPendantAddEquipCache(t *testing.T) {
  100. convey.Convey("AddEquipCache", t, func(ctx convey.C) {
  101. var (
  102. mid = int64(650454)
  103. info = &model.PendantEquip{}
  104. )
  105. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  106. err := d.AddEquipCache(c, mid, info)
  107. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  108. ctx.So(err, convey.ShouldBeNil)
  109. })
  110. })
  111. })
  112. }
  113. func TestPendantequipCache(t *testing.T) {
  114. convey.Convey("equipCache", t, func(ctx convey.C) {
  115. var (
  116. mid = int64(650454)
  117. )
  118. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  119. info, err := d.equipCache(c, mid)
  120. ctx.Convey("Then err should be nil.info should not be nil.", func(ctx convey.C) {
  121. ctx.So(err, convey.ShouldBeNil)
  122. ctx.So(info, convey.ShouldNotBeNil)
  123. })
  124. })
  125. })
  126. }
  127. func TestPendantDelEquipCache(t *testing.T) {
  128. convey.Convey("DelEquipCache", t, func(ctx convey.C) {
  129. var (
  130. mid = int64(650454)
  131. )
  132. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  133. err := d.DelEquipCache(c, mid)
  134. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  135. ctx.So(err, convey.ShouldBeNil)
  136. })
  137. })
  138. })
  139. }
  140. func TestPendantequipsCache(t *testing.T) {
  141. convey.Convey("equipsCache", t, func(ctx convey.C) {
  142. var (
  143. mids = []int64{650454}
  144. )
  145. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  146. p1, p2, err := d.equipsCache(c, mids)
  147. ctx.Convey("Then err should be nil.p1,p2 should not be nil.", func(ctx convey.C) {
  148. ctx.So(err, convey.ShouldBeNil)
  149. ctx.So(p2, convey.ShouldNotBeNil)
  150. ctx.So(p1, convey.ShouldNotBeNil)
  151. })
  152. })
  153. })
  154. }
  155. func TestPendantDelEquipsCache(t *testing.T) {
  156. convey.Convey("DelEquipsCache", t, func(ctx convey.C) {
  157. var (
  158. mids = []int64{650454, 1}
  159. )
  160. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  161. err := d.DelEquipsCache(c, mids)
  162. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  163. ctx.So(err, convey.ShouldBeNil)
  164. })
  165. })
  166. })
  167. }