Skip to content

olomix/go-test-redis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-test-redis

Helper tool to test Go programs against Redis

go-test-redis expects the redis server address in REDISADDR environment variable. If it is empty, default address is :6379.

Example:

import "github.com/olomix/go-test-redis/v2"

func TestCache(t *testing.T) {
	rdb := go_test_redis.WithRedis(t)
	if err := rdb.Ping(context.Background()).Err(); err != nil {
		t.Fatal(err)
	}
}

WithRedis looking for the empty database and locks it to prevent other parallel tests to use the same database. If all databases are busy, we are waiting for free one.

When we need to wait for redis to be available in CI if it starting in paralle container, we can use WaitForRedis helper. Example:

func TestMain(m *testing.M) {
	err :=
		go_test_redis.WaitForRedis(go_test_redis.WithTimeout(30 * time.Second))
	if err != nil {
		panic(err)
	}

	os.Exit(m.Run())
}

If we skip WithTimeout option, 5 seconds is the default one.

About

Helper tool to test Go programs against Redis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages