Documentation
¶
Index ¶
- type Cmd
- type Conn
- func (c *Conn) Clear()
- func (c *Conn) Close() error
- func (c *Conn) Command(commandName string, args ...interface{}) *Cmd
- func (c *Conn) Do(commandName string, args ...interface{}) (reply interface{}, err error)
- func (c *Conn) Err() error
- func (c *Conn) Flush() error
- func (c *Conn) GenericCommand(commandName string) *Cmd
- func (c *Conn) Receive() (reply interface{}, err error)
- func (c *Conn) Script(scriptData []byte, keyCount int, args ...interface{}) *Cmd
- func (c *Conn) Send(commandName string, args ...interface{}) error
- func (c Conn) Stats(cmd *Cmd) int
- type FuzzyMatcher
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct {
Name string // Name of the command
Args []interface{} // Arguments of the command
Responses []Response // Slice of returned responses
Callback callback // Callback will always be called, Responses ignored
// contains filtered or unexported fields
}
Cmd stores the registered information about a command to return it later when request by a command execution
func (*Cmd) Expect ¶
Expect sets a response for this command. Everytime a Do or Receive methods are executed for a registered command this response or error will be returned. Expect call returns a pointer to Cmd struct, so you can chain Expect calls. Chained responses will be returned on subsequent calls matching this commands arguments in FIFO order
func (*Cmd) ExpectCallback ¶
ExpectCallback register callback function to return response result
func (*Cmd) ExpectError ¶
ExpectError allows you to force an error when executing a command/arguments
type Conn ¶
type Conn struct {
ReceiveWait bool // When set to true, Receive method will wait for a value in ReceiveNow channel to proceed, this is useful in a PubSub scenario
ReceiveNow chan bool // Used to lock Receive method to simulate a PubSub scenario
CloseMock func() error // Mock the redigo Close method
ErrMock func() error // Mock the redigo Err method
FlushMock func() error // Mock the redigo Flush method
// contains filtered or unexported fields
}
Conn is the struct that can be used where you inject the redigo.Conn on your project
func NewConn ¶
func NewConn() *Conn
NewConn returns a new mocked connection. Obviously as we are mocking we don't need any Redis connection parameter
func NewFakeRedis ¶
func NewFakeRedis() *Conn
NewFakeRedis returns a connection, that acts as real redis
func (*Conn) Clear ¶
func (c *Conn) Clear()
Clear removes all registered commands. Useful for connection reuse in test scenarios
func (*Conn) Command ¶
Command register a command in the mock system using the same arguments of a Do or Send commands. It will return a registered command object where you can set the response or error
func (*Conn) Do ¶
Do looks in the registered commands (via Command function) if someone matches with the given command name and arguments, if so the corresponding response or error is returned. If no registered command is found an error is returned
func (*Conn) GenericCommand ¶
GenericCommand register a command without arguments. If a command with arguments doesn't match with any registered command, it will look for generic commands before throwing an error
func (*Conn) Receive ¶
Receive will process the queue created by the Send method, only one item of the queue is processed by Receive call. It will work as the Do method
func (*Conn) Script ¶
Script registers a command in the mock system just like Command method would do. The first argument is a byte array with the script text, next ones are the ones you would pass to redis Script.Do() method
type FuzzyMatcher ¶
type FuzzyMatcher interface {
// Match takes an argument passed to mock connection Do call and check if
// it fulfills constraints set in concrete implementation of this interface
Match(interface{}) bool
}
FuzzyMatcher is an interface that exports exports one function. It can be passed to the Command as a argument. When the command is evaluated agains data provided in mock connection Do call, FuzzyMatcher will call Match on the argument and returns true if argument fulfils constraints set in concrete implementation
func NewAnyData ¶
func NewAnyData() FuzzyMatcher
NewAnyData returns a FuzzyMatcher instance matching every data passed as an arguments (returns true by default)
func NewAnyDataArray ¶
func NewAnyDataArray() FuzzyMatcher
NewAnyDataArray returns a FuzzyMatcher instance matching every data passed as an arguments (returns true by default) and ignore arguments length
func NewAnyDouble ¶
func NewAnyDouble() FuzzyMatcher
NewAnyDouble returns a FuzzyMatcher instance mathing any double passed as an argument
func NewAnyInt ¶
func NewAnyInt() FuzzyMatcher
NewAnyInt returns a FuzzyMatcher instance matching any integer passed as an argument
