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.
- Host: GitHub
- URL: https://github.com/arhea/go-mock-redis
- Owner: arhea
- License: mit
- Created: 2023-12-02T15:27:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-11T23:21:35.000Z (about 1 year ago)
- Last Synced: 2025-01-17T23:25:45.044Z (3 months ago)
- Topics: golang, golang-module, golang-package, test, testcon, testcontainers-go
- Language: Go
- Homepage: https://pkg.go.dev/github.com/arhea/go-mock-redis
- Size: 59.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# 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
}
```