From 2773141b4debd008fb6bf5250290c142e737fe41 Mon Sep 17 00:00:00 2001 From: "tung.tq" Date: Wed, 15 Feb 2023 15:57:24 +0700 Subject: [PATCH] Improve Fake Client --- fake/fake.go | 12 ++++++++++-- fake/fake_test.go | 13 +++++++------ item/item_test.go | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fake/fake.go b/fake/fake.go index 5008400..22afc74 100644 --- a/fake/fake.go +++ b/fake/fake.go @@ -1,6 +1,7 @@ package fake import ( + "context" "github.com/QuangTung97/memproxy" "github.com/QuangTung97/memproxy/mocks" "sync" @@ -22,6 +23,8 @@ type Memcache struct { entries map[string]Entry } +var _ memproxy.Memcache = &Memcache{} + // New ... func New() *Memcache { return &Memcache{ @@ -36,10 +39,10 @@ func (m *Memcache) nextCAS() uint64 { return m.cas } -// NewPipeline returns a Fake Pipeline +// Pipeline returns a Fake Pipeline // //revive:disable-next-line:cognitive-complexity -func (m *Memcache) NewPipeline() memproxy.Pipeline { +func (m *Memcache) Pipeline(_ context.Context, _ ...memproxy.PipelineOption) memproxy.Pipeline { sess := m.sessProvider.New() var calls []func() doCalls := func() { @@ -160,3 +163,8 @@ func (m *Memcache) NewPipeline() memproxy.Pipeline { return pipe } + +// Close ... +func (*Memcache) Close() error { + return nil +} diff --git a/fake/fake_test.go b/fake/fake_test.go index 64dc829..82a6550 100644 --- a/fake/fake_test.go +++ b/fake/fake_test.go @@ -1,6 +1,7 @@ package fake import ( + "context" "github.com/QuangTung97/memproxy" "github.com/stretchr/testify/assert" "testing" @@ -8,7 +9,7 @@ import ( func newPipelineTest() memproxy.Pipeline { mc := New() - return mc.NewPipeline() + return mc.Pipeline(context.Background()) } func TestPipeline(t *testing.T) { @@ -151,7 +152,7 @@ func TestPipeline(t *testing.T) { func TestPipeline__Do_Finish(t *testing.T) { t.Run("call-finish", func(t *testing.T) { mc := New() - pipe1 := mc.NewPipeline() + pipe1 := mc.Pipeline(context.Background()) resp1, err := pipe1.LeaseGet("KEY01", memproxy.LeaseGetOptions{})() assert.Equal(t, nil, err) @@ -160,7 +161,7 @@ func TestPipeline__Do_Finish(t *testing.T) { pipe1.Finish() - pipe2 := mc.NewPipeline() + pipe2 := mc.Pipeline(context.Background()) resp2, err := pipe2.LeaseGet("KEY01", memproxy.LeaseGetOptions{})() assert.Equal(t, nil, err) @@ -173,7 +174,7 @@ func TestPipeline__Do_Finish(t *testing.T) { t.Run("call-execute", func(t *testing.T) { mc := New() - pipe1 := mc.NewPipeline() + pipe1 := mc.Pipeline(context.Background()) resp1, err := pipe1.LeaseGet("KEY01", memproxy.LeaseGetOptions{})() assert.Equal(t, nil, err) @@ -182,7 +183,7 @@ func TestPipeline__Do_Finish(t *testing.T) { pipe1.Execute() - pipe2 := mc.NewPipeline() + pipe2 := mc.Pipeline(context.Background()) resp2, err := pipe2.LeaseGet("KEY01", memproxy.LeaseGetOptions{})() assert.Equal(t, nil, err) @@ -195,7 +196,7 @@ func TestPipeline__Do_Finish(t *testing.T) { t.Run("lower-session", func(t *testing.T) { mc := New() - pipe := mc.NewPipeline() + pipe := mc.Pipeline(context.Background()) sess := pipe.LowerSession() diff --git a/item/item_test.go b/item/item_test.go index 081dc56..89bb50c 100644 --- a/item/item_test.go +++ b/item/item_test.go @@ -1010,7 +1010,7 @@ func TestMultiGetFiller(t *testing.T) { func TestItem_WithFakePipeline(t *testing.T) { mc := fake.New() - pipe := mc.NewPipeline() + pipe := mc.Pipeline(newContext()) fillCalls := 0