mc_test.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package block
  2. import (
  3. "context"
  4. "reflect"
  5. "testing"
  6. "go-common/library/cache/memcache"
  7. "github.com/bouk/monkey"
  8. "github.com/smartystreets/goconvey/convey"
  9. )
  10. func TestBlockuserKey(t *testing.T) {
  11. convey.Convey("userKey", t, func(convCtx convey.C) {
  12. var (
  13. mid = int64(0)
  14. )
  15. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  16. key := userKey(mid)
  17. convCtx.Convey("Then key should not be nil.", func(convCtx convey.C) {
  18. convCtx.So(key, convey.ShouldNotBeNil)
  19. })
  20. })
  21. })
  22. }
  23. func TestBlocksyncBlockTypeID(t *testing.T) {
  24. convey.Convey("syncBlockTypeID", t, func(convCtx convey.C) {
  25. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  26. key := syncBlockTypeID()
  27. convCtx.Convey("Then key should not be nil.", func(convCtx convey.C) {
  28. convCtx.So(key, convey.ShouldNotBeNil)
  29. })
  30. })
  31. })
  32. }
  33. func TestBlockSetSyncBlockTypeID(t *testing.T) {
  34. convey.Convey("SetSyncBlockTypeID", t, func(convCtx convey.C) {
  35. var (
  36. c = context.Background()
  37. id = int64(0)
  38. )
  39. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  40. err := d.SetSyncBlockTypeID(c, id)
  41. convCtx.Convey("Then err should be nil.", func(convCtx convey.C) {
  42. convCtx.So(err, convey.ShouldBeNil)
  43. })
  44. })
  45. })
  46. }
  47. func TestBlockSyncBlockTypeID(t *testing.T) {
  48. convey.Convey("SyncBlockTypeID", t, func(convCtx convey.C) {
  49. var (
  50. c = context.Background()
  51. )
  52. convCtx.Convey("When everything goes positive", func(convCtx convey.C) {
  53. id, err := d.SyncBlockTypeID(c)
  54. convCtx.Convey("Then err should be nil.id should not be nil.", func(convCtx convey.C) {
  55. convCtx.So(err, convey.ShouldBeNil)
  56. convCtx.So(id, convey.ShouldNotBeNil)
  57. })
  58. })
  59. })
  60. }
  61. func TestBlockDeleteUserCache(t *testing.T) {
  62. convey.Convey("DeleteUserCache", t, func(convCtx convey.C) {
  63. var (
  64. c = context.Background()
  65. mid = int64(0)
  66. )
  67. convCtx.Convey("connect memcache failed", func(convCtx convey.C) {
  68. guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.mc), "Get", func(_ *memcache.Pool, _ context.Context) memcache.Conn {
  69. return memcache.MockWith(memcache.ErrConnClosed)
  70. })
  71. defer guard.Unpatch()
  72. err := d.DeleteUserCache(c, mid)
  73. convCtx.Convey("Then err should not be nil.", func(convCtx convey.C) {
  74. convCtx.So(err, convey.ShouldNotBeNil)
  75. })
  76. })
  77. })
  78. }