An open API service indexing awesome lists of open source software.

https://github.com/arhea/go-mock-redis

Provides convenient test helpers for mocking Redis containers and Redis clients.
https://github.com/arhea/go-mock-redis

golang golang-module golang-package test testcon testcontainers-go

Last synced: about 2 months ago
JSON representation

Provides convenient test helpers for mocking Redis containers and Redis clients.

Awesome Lists containing this project

README

        

# Mock Redis

![Tests](https://github.com/arhea/go-mock-redis/actions/workflows/main.yml/badge.svg?branch=main) ![goreportcard](https://goreportcard.com/badge/github.com/arhea/go-mock-redis)

Provide a mock Redis instance and optionally a mock Redis client for testing purposes. This library is built so you can
mock Redis instances using real Redis containers. You will need to have Docker running on your local machine or within
your CI environment.

This library is built on top of [testcontainers](https://testcontainers.com/).

## Usage

Creating a mock instance for creating a customer connection.

```golang
func TestXXX(t *testing.T) {
ctx := context.Background()

mock, err := mockredis.NewInstance(ctx, t)

if err != nil {
t.Fatalf("creating the instance: %v", err)
return
}

// close the mock
defer mock.Close(ctx)

// ... my test code
}
```

Creating a mock redis client for interacting with Redis.

```golang
func TestXXX(t *testing.T) {
ctx := context.Background()

mock, err := mockredis.NewClient(ctx, t)

if err != nil {
t.Fatalf("creating the client: %v", err)
return
}

// close the mock
defer mock.Close(ctx)

redisClient := mock.Client()

// ... my test code
}
```