redis_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package dao
  2. import (
  3. "context"
  4. "testing"
  5. "go-common/app/service/main/share/model"
  6. "github.com/smartystreets/goconvey/convey"
  7. )
  8. func TestDaoRedisKey(t *testing.T) {
  9. var (
  10. oid = int64(0)
  11. tp = int(0)
  12. )
  13. convey.Convey("redisKey", t, func(ctx convey.C) {
  14. p1 := redisKey(oid, tp)
  15. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  16. ctx.So(p1, convey.ShouldNotBeNil)
  17. })
  18. })
  19. }
  20. func TestDaoRedisValue(t *testing.T) {
  21. convey.Convey("redisValue", t, func(ctx convey.C) {
  22. p := &model.ShareParams{
  23. OID: 22,
  24. MID: 33,
  25. TP: 2,
  26. IP: "",
  27. }
  28. p1 := redisValue(p)
  29. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  30. ctx.So(p1, convey.ShouldNotBeNil)
  31. })
  32. })
  33. }
  34. func TestDaoShareKey(t *testing.T) {
  35. var (
  36. oid = int64(0)
  37. tp = int(0)
  38. )
  39. convey.Convey("shareKey", t, func(ctx convey.C) {
  40. p1 := shareKey(oid, tp)
  41. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  42. ctx.So(p1, convey.ShouldNotBeNil)
  43. })
  44. })
  45. }
  46. func TestDaoAddShareMember(t *testing.T) {
  47. convey.Convey("AddShareMember", t, func(ctx convey.C) {
  48. p := &model.ShareParams{
  49. OID: int64(1),
  50. MID: int64(1),
  51. TP: int(3),
  52. }
  53. ok, err := d.AddShareMember(context.Background(), p)
  54. ctx.Convey("Then err should be nil.ok should not be nil.", func(ctx convey.C) {
  55. ctx.So(err, convey.ShouldBeNil)
  56. ctx.So(ok, convey.ShouldNotBeNil)
  57. })
  58. })
  59. }
  60. func TestDaoSetShareCache(t *testing.T) {
  61. var (
  62. c = context.TODO()
  63. oid = int64(0)
  64. tp = int(0)
  65. shared = int64(0)
  66. )
  67. convey.Convey("SetShareCache", t, func(ctx convey.C) {
  68. err := d.SetShareCache(c, oid, tp, shared)
  69. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  70. ctx.So(err, convey.ShouldBeNil)
  71. })
  72. })
  73. }
  74. func TestDaoShareCache(t *testing.T) {
  75. var (
  76. c = context.TODO()
  77. oid = int64(0)
  78. tp = int(0)
  79. )
  80. convey.Convey("ShareCache", t, func(ctx convey.C) {
  81. shared, err := d.ShareCache(c, oid, tp)
  82. ctx.Convey("Then err should be nil.shared should not be nil.", func(ctx convey.C) {
  83. ctx.So(err, convey.ShouldBeNil)
  84. ctx.So(shared, convey.ShouldNotBeNil)
  85. })
  86. })
  87. }
  88. func TestDaoSharesCache(t *testing.T) {
  89. var (
  90. c = context.TODO()
  91. oids = []int64{}
  92. tp = int(0)
  93. )
  94. convey.Convey("SharesCache", t, func(ctx convey.C) {
  95. shares, err := d.SharesCache(c, oids, tp)
  96. ctx.Convey("Then err should be nil.shares should not be nil.", func(ctx convey.C) {
  97. ctx.So(err, convey.ShouldBeNil)
  98. ctx.So(shares, convey.ShouldNotBeNil)
  99. })
  100. })
  101. }