Would consider defining an interface for redis.Client so it is possible to drop in a mock during testing?
type Client struct {
baseClient
cmdable
}
Compare to InfluxDB where client.Client easily can be replaced with just a couple of lines of code:
type dummyClient struct {
}
func (dc *dummyClient) Ping(timeout time.Duration) (time.Duration, string, error) {
return nil, "", nil
}
func (dc *dummyClient) Write(bp client.BatchPoints) error {
return nil
}
func (dc *dummyClient) Query(q client.Query) (*client.Response, error) {
return nil, nil
}
func (dc *dummyClient) Close() error {
return nil
}
We already have https://godoc.org/gopkg.in/redis.v5#Cmdable and UniversalClient
The Cmdable interface is huge - there are almost 200 calls to mock. Any chance that it can be broken up into a couple of smaller interfaces?
Simple, just embed the interface and moc/implement the methods you are using:
type myMockType struct {
redis.Cmdable
}
func (c *myMockType) Ping() *redis.StatusCommand {
...
}
Ah, didn't think of that! I'll try that, and submit a diff to document how to do it...
Most helpful comment
We already have https://godoc.org/gopkg.in/redis.v5#Cmdable and UniversalClient