Skip to content

bitcoin-sv/testcontainers-redis-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

testcontainers-redis-go

Go Reference Go Report Card

Go library for Redis integration testing via Testcontainers.

Install

Use go get to install the latest version of the library.

go get -u github.com/bitcoin-sv/testcontainers-redis-go@latest

Usage

import (
    "context"
    "fmt"
    "testing"

    "github.com/stretchr/testify/require"
    redis_db "github.com/redis/go-redis/v9"
    redisTest "github.com/bitcoin-sv/testcontainers-redis-go"
)

func TestRedis(t *testing.T) {
    redisClient := setupRedis(t)
    // your code here
}

func setupRedis(t *testing.T) *redis_db.Client {
    ctx := context.Background()

    container, err := redisTest.RunContainer(ctx)
    require.NoError(t, err)
    
    t.Cleanup(func() {
        err := container.Terminate(ctx)
        require.NoError(t, err)
    })

    host, err := container.Host(ctx)
    require.NoError(t, err)
    
    port, err := container.ServicePort(ctx)
    require.NoError(t, err)

    client, err := redis_db.NewClient(&redis_db.Options{
        Addr: fmt.Sprintf("%s:%d", host, port),
    })
    require.NoError(t, err)

    return client
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages