Skip to content

Commit

Permalink
feat: test code
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 authored and actions-user committed Jul 30, 2020
1 parent 959c564 commit 22271bd
Show file tree
Hide file tree
Showing 3 changed files with 379 additions and 174 deletions.
6 changes: 3 additions & 3 deletions internal/db/kvs/redis/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
defaultOpts = []Option{
WithInitialPingDuration("30ms"),
WithInitialPingTimeLimit("5m"),
WithPingFlag(true),
WithPing(true),
}
)

Expand Down Expand Up @@ -324,9 +324,9 @@ func WithInitialPingDuration(dur string) Option {
}
}

func WithPingFlag(flag bool) Option {
func WithPing(enabled bool) Option {
return func(r *redisClient) error {
r.pingEnabled = flag
r.pingEnabled = enabled
return nil
}
}
38 changes: 38 additions & 0 deletions internal/db/kvs/redis/redis_mock_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package redis

import redis "github.com/go-redis/redis/v7"

type MockRedis struct {
TxPipelineFunc func() redis.Pipeliner
PingFunc func() *StatusCmd
CloseFunc func() error
GetFunc func(string) *redis.StringCmd
MGetFunc func(...string) *redis.SliceCmd
DelFunc func(keys ...string) *redis.IntCmd
}

var _ = (*MockRedis)(nil)

func (m *MockRedis) TxPipeline() redis.Pipeliner {
return m.TxPipelineFunc()
}

func (m *MockRedis) Ping() *StatusCmd {
return m.PingFunc()
}

func (m *MockRedis) Close() error {
return m.CloseFunc()
}

func (m *MockRedis) Get(key string) *redis.StringCmd {
return m.GetFunc(key)
}

func (m *MockRedis) MGet(keys ...string) *redis.SliceCmd {
return m.MGetFunc(keys...)
}

func (m *MockRedis) Del(keys ...string) *redis.IntCmd {
return m.DelFunc(keys...)
}
Loading

0 comments on commit 22271bd

Please sign in to comment.