mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
Signed-off-by: fukua95 <[email protected]> Co-authored-by: Nedyalko Dyakov <[email protected]>
27 lines
558 B
Go
27 lines
558 B
Go
package redis
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
// mockCmdable is a mock implementation of cmdable that records the last command.
|
|
// This is used for unit testing command construction without requiring a Redis server.
|
|
type mockCmdable struct {
|
|
lastCmd Cmder
|
|
returnErr error
|
|
}
|
|
|
|
func (m *mockCmdable) call(_ context.Context, cmd Cmder) error {
|
|
m.lastCmd = cmd
|
|
if m.returnErr != nil {
|
|
cmd.SetErr(m.returnErr)
|
|
}
|
|
return m.returnErr
|
|
}
|
|
|
|
func (m *mockCmdable) asCmdable() cmdable {
|
|
return func(ctx context.Context, cmd Cmder) error {
|
|
return m.call(ctx, cmd)
|
|
}
|
|
}
|