Skip to content

Commit

Permalink
Improve Fake Client
Browse files Browse the repository at this point in the history
  • Loading branch information
tung.tq committed Feb 15, 2023
1 parent 5cf7b77 commit 2773141
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
12 changes: 10 additions & 2 deletions fake/fake.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fake

import (
"context"
"github.com/QuangTung97/memproxy"
"github.com/QuangTung97/memproxy/mocks"
"sync"
Expand All @@ -22,6 +23,8 @@ type Memcache struct {
entries map[string]Entry
}

var _ memproxy.Memcache = &Memcache{}

// New ...
func New() *Memcache {
return &Memcache{
Expand All @@ -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() {
Expand Down Expand Up @@ -160,3 +163,8 @@ func (m *Memcache) NewPipeline() memproxy.Pipeline {

return pipe
}

// Close ...
func (*Memcache) Close() error {
return nil
}
13 changes: 7 additions & 6 deletions fake/fake_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package fake

import (
"context"
"github.com/QuangTung97/memproxy"
"github.com/stretchr/testify/assert"
"testing"
)

func newPipelineTest() memproxy.Pipeline {
mc := New()
return mc.NewPipeline()
return mc.Pipeline(context.Background())
}

func TestPipeline(t *testing.T) {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion item/item_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2773141

Please sign in to comment.