memcache_test.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package account
  2. import (
  3. "context"
  4. accmdl "go-common/app/interface/main/creative/model/account"
  5. "go-common/library/cache/memcache"
  6. "reflect"
  7. "testing"
  8. "github.com/bouk/monkey"
  9. "github.com/smartystreets/goconvey/convey"
  10. )
  11. func TestAccountlimitMidHafMin(t *testing.T) {
  12. var (
  13. mid = int64(2089809)
  14. )
  15. convey.Convey("limitMidHafMin", t, func(ctx convey.C) {
  16. p1 := limitMidHafMin(mid)
  17. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  18. ctx.So(p1, convey.ShouldNotBeNil)
  19. })
  20. })
  21. }
  22. func TestAccountkeyUpInfo(t *testing.T) {
  23. var (
  24. mid = int64(2089809)
  25. )
  26. convey.Convey("keyUpInfo", t, func(ctx convey.C) {
  27. p1 := keyUpInfo(mid)
  28. ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
  29. ctx.So(p1, convey.ShouldNotBeNil)
  30. })
  31. })
  32. }
  33. func TestAccountHalfMin(t *testing.T) {
  34. var (
  35. c = context.TODO()
  36. mid = int64(2089809)
  37. )
  38. convey.Convey("HalfMin", t, func(ctx convey.C) {
  39. exist, ts, err := d.HalfMin(c, mid)
  40. ctx.Convey("Then err should be nil.exist,ts should not be nil.", func(ctx convey.C) {
  41. ctx.So(err, convey.ShouldBeNil)
  42. ctx.So(ts, convey.ShouldNotBeNil)
  43. ctx.So(exist, convey.ShouldNotBeNil)
  44. })
  45. })
  46. }
  47. func TestAccountUpInfoCache(t *testing.T) {
  48. var (
  49. c = context.TODO()
  50. mid = int64(2089809)
  51. )
  52. convey.Convey("UpInfoCache", t, func(ctx convey.C) {
  53. connGuard := monkey.PatchInstanceMethod(reflect.TypeOf(d.mc), "Get", func(_ *memcache.Pool, _ context.Context) memcache.Conn {
  54. return memcache.MockWith(memcache.ErrNotFound)
  55. })
  56. defer connGuard.Unpatch()
  57. st, err := d.UpInfoCache(c, mid)
  58. ctx.Convey("Then err should be nil.st should not be nil.", func(ctx convey.C) {
  59. ctx.So(err, convey.ShouldBeNil)
  60. ctx.So(st, convey.ShouldBeNil)
  61. })
  62. })
  63. }
  64. func TestAccountAddUpInfoCache(t *testing.T) {
  65. var (
  66. c = context.TODO()
  67. mid = int64(2089809)
  68. st = &accmdl.UpInfo{}
  69. )
  70. convey.Convey("AddUpInfoCache", t, func(ctx convey.C) {
  71. connGuard := monkey.PatchInstanceMethod(reflect.TypeOf(d.mc), "Get", func(_ *memcache.Pool, _ context.Context) memcache.Conn {
  72. return memcache.MockWith(nil)
  73. })
  74. defer connGuard.Unpatch()
  75. err := d.AddUpInfoCache(c, mid, st)
  76. ctx.Convey("Then err should be nil.", func(ctx convey.C) {
  77. ctx.So(err, convey.ShouldBeNil)
  78. })
  79. })
  80. }