Skip to content

Commit

Permalink
These commits update the v8 add ClusterClient support (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvlgo authored Apr 15, 2022
1 parent 1fac9c5 commit 2a654be
Showing 1 changed file with 57 additions and 2 deletions.
59 changes: 57 additions & 2 deletions v8/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package redismock

import (
"context"
"sync"

"github.com/go-redis/redis/v8"
Expand All @@ -17,7 +18,61 @@ type ClientMock struct {

mock.Mock
redis.Cmdable
client *redis.Client
client redis.UniversalClient
Ctx context.Context
}

func (m *ClientMock) Context() context.Context {
return m.Ctx
}

func (m *ClientMock) AddHook(hook redis.Hook) {
m.client.AddHook(hook)
}

func (m *ClientMock) Do(ctx context.Context, args ...interface{}) *redis.Cmd {
if !m.hasStub("Do") {
return m.client.Do(ctx, args)
}
return m.Called().Get(0).(*redis.Cmd)
}

func (m *ClientMock) Process(ctx context.Context, cmd redis.Cmder) error {
if !m.hasStub("Process") {
return m.client.Process(ctx, cmd)
}
args := m.Called()
return args.Get(0).(error)
}

func (m *ClientMock) Subscribe(ctx context.Context, channels ...string) *redis.PubSub {
if !m.hasStub("Subscribe") {
return m.client.Subscribe(ctx, channels...)
}
return m.Called().Get(0).(*redis.PubSub)
}

func (m *ClientMock) PSubscribe(ctx context.Context, channels ...string) *redis.PubSub {

if !m.hasStub("PSubscribe") {
return m.client.PSubscribe(ctx, channels...)
}
return m.Called().Get(0).(*redis.PubSub)
}

func (m *ClientMock) Close() error {
if !m.hasStub("Close") {
return m.client.Close()
}
args := m.Called()
return args.Get(0).(error)
}

func (m *ClientMock) PoolStats() *redis.PoolStats {
if !m.hasStub("PoolStats") {
return m.client.PoolStats()
}
return m.Called().Get(0).(*redis.PoolStats)
}

// NewMock creates a hollow mock. You will need to stub all commands that you
Expand All @@ -34,7 +89,7 @@ func NewMock() *ClientMock {
//
// This is most useful when you want a real Redis instance, but you need to stub
// off certain commands or behaviors. See NewMock().
func NewNiceMock(client *redis.Client) *ClientMock {
func NewNiceMock(client redis.UniversalClient) *ClientMock {
m := NewMock()
m.client = client

Expand Down

0 comments on commit 2a654be

Please sign in to comment.