When testing our applications we often have a lot of external dependencies, and often we’re not running our tests in an environment where we have room to boot up Redis, MySQL etc.
Recently I was trying to solve the problem of needing a Redis connection in one of my applications, but I didn’t want to have to keep a Redis server running whilst I ran my tests, I felt this was unnecessary.
I stumbled upon an elegant solution to this: https://github.com/alicebob/miniredis
This library spins up a Redis compatible server in your application that you can use without dependencies when running your tests in any environment. This is perfect!
Say in your application you’re making use of a redisClient
which is available globally in your package scope:
In this case we’re using _github.com/go-redis/redis_
as our Redis library of choice.
#redis #programming #golang #tdd #testing