dao.cache_test.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/library/ecode"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoInfo(t *testing.T) {
  9. var (
  10. c = context.TODO()
  11. id = int64(1405)
  12. )
  13. convey.Convey("Get base-info from cache if miss will call source method", t, func(ctx convey.C) {
  14. res, err := d.Info(c, id)
  15. ctx.Convey("Then err should be nil and res should be not nil.", func(ctx convey.C) {
  16. ctx.So(err, convey.ShouldBeNil)
  17. ctx.So(res, convey.ShouldNotBeNil)
  18. })
  19. })
  20. }
  21. func TestDaoInfos(t *testing.T) {
  22. var (
  23. c = context.TODO()
  24. keys = []int64{110020171, 110019841}
  25. )
  26. convey.Convey("Batch get base-infos from cache if miss will call source method", t, func(ctx convey.C) {
  27. res, err := d.Infos(c, keys)
  28. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  29. ctx.So(err, convey.ShouldBeNil)
  30. ctx.So(res, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func TestDaoCard(t *testing.T) {
  35. var (
  36. c = context.TODO()
  37. id = int64(110020171)
  38. )
  39. convey.Convey("Get card-info from cache if miss will call source method", t, func(ctx convey.C) {
  40. res, err := d.Card(c, id)
  41. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  42. ctx.So(err, convey.ShouldBeNil)
  43. ctx.So(res, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func TestDaoCards(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. keys = []int64{110020171, 110019841}
  51. )
  52. convey.Convey("Batch get card-info from cache if miss will call source method", t, func(ctx convey.C) {
  53. res, err := d.Cards(c, keys)
  54. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(res, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func TestDaoVip(t *testing.T) {
  61. var (
  62. c = context.TODO()
  63. id = int64(110018881)
  64. )
  65. convey.Convey("Get vip-info from cache if miss will call source method", t, func(ctx convey.C) {
  66. res, err := d.Vip(c, id)
  67. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  68. ctx.So(err, convey.ShouldBeNil)
  69. ctx.So(res, convey.ShouldNotBeNil)
  70. })
  71. })
  72. }
  73. func TestDaoAutoRenewVip(t *testing.T) {
  74. var (
  75. c = context.TODO()
  76. autoRenewMid = int64(27515232)
  77. )
  78. convey.Convey("Get vip-info from cache if miss will call source method", t, func(ctx convey.C) {
  79. res, err := d.Vip(c, autoRenewMid)
  80. t.Logf("data(%+v)", res)
  81. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  82. ctx.So(err, convey.ShouldBeNil)
  83. ctx.So(res, convey.ShouldNotBeNil)
  84. })
  85. })
  86. }
  87. func TestDaoVips(t *testing.T) {
  88. var (
  89. c = context.TODO()
  90. keys = []int64{1405, 2205}
  91. )
  92. convey.Convey("Batch get vip-info from cache if miss will call source method", t, func(ctx convey.C) {
  93. res, err := d.Vips(c, keys)
  94. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  95. ctx.So(err, convey.ShouldBeNil)
  96. ctx.So(res, convey.ShouldNotBeNil)
  97. })
  98. })
  99. }
  100. func TestDaoProfile(t *testing.T) {
  101. var (
  102. c = context.TODO()
  103. id = int64(111003471)
  104. )
  105. convey.Convey("Get profile-info from cache if miss will call source method", t, func(ctx convey.C) {
  106. res, err := d.Profile(c, id)
  107. if err == ecode.Degrade {
  108. err = nil
  109. }
  110. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  111. ctx.So(err, convey.ShouldBeNil)
  112. ctx.So(res, convey.ShouldNotBeNil)
  113. })
  114. })
  115. }