go-redis / redismock

Redis client Mock
https://redis.uptrace.dev
BSD 2-Clause "Simplified" License
280 stars 60 forks source link

How to test client-unsupported commands via client.Do() #25

Open ideasculptor opened 2 years ago

ideasculptor commented 2 years ago

It seems as though there is no way to test code which uses client-unsupported commands via: client.Do(ctx, "cmd", ...args)

There definitely seems to be no example and I see no Issues filed which mention it, and there is no immediately obvious way to set an expectation for an arbitrary Cmd when looking at the source code. This prevents testing of any code which uses a custom redis module to provide commands not natively supported by the redis client, which seems like a relatively common use case, so I'm wondering if this is an oversight in the documentation and example code?

ideasculptor commented 2 years ago

I should elaborate - my code actually uses a pipeline to execute multiple custom commands.

    cmd := pipe.Do(ctx, "CL.THROTTLE", req.key, req.maxBurst, req.limit, req.period*time.Second, 1)

which is eventually executed via:

    cmders, err := pipe.Exec(ctx)

Given the example code for testing pipeline, I would imagine that if Do() were supported, pipelining Do() would also be supported by setting an expectation for each pipelined command.