Testing a Go Package That Depends on Redis
Redsync, one of my open-source Go packages, implements a distributed lock using Redis. It is an implementation of the Redlock algorithm.
This Go package has tests that run against multiple real Redis servers. And it is an example of how you can use the TestMain
function to customize your Go tests.
The TestMain
function, if defined in your Go tests, will allow you to run the Go code before and after the actual tests, which is really ideal for setup and teardown work.
In the case of Redsync, the TestMain
function is where multiple Redis servers spawn before running the tests. A Go package, tempredis
, makes it easy to start Redis servers without having to muck around with exec.Command
.
|
|
When any tests run in this package, servers
will have instances of *tempredis.Server
.
|
|
This post is 90th of my #100DaysToOffload challenge. Want to get involved? Find out more at 100daystooffload.com.
comments powered by Disqus