go-redis / redismock

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

Cannot mock non-string parameters #85

Open jamierajewski opened 11 months ago

jamierajewski commented 11 months ago

I noticed that there doesn't seem to be a way to mock non-string parameters; for example, I have a function that calculates a duration to be used as the TTL for PExpire and does not expose it such that I can use it in my test. This means I cannot mock cases that call this function since there is no way to know the TTL at the time of test execution.

We have regex matching or a custom matcher function that are supported for string arguments, but there doesn't seem to be a way to mock non-string parameters.

Example:

// The key can be matched with regex but not the duration
mockConfig.Regexp().ExpectPExpire(`^[a-fA-F0-9]{32}/\d+$`, <some duration>).RedisNil()