Discover Packages
github.com/etecs-ru/gnomock
preset
redis
package
Version:
v0.13.2
Opens a new window with list of versions in this module.
Published: Apr 4, 2021
License: MIT
Opens a new window with license information.
Imports: 5
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
README
¶
Gnomock Redis
Gnomock Redis is a Gnomock preset for running tests against a real Redis
container, without mocks.
package redis_test
import (
"fmt"
"testing"
redisclient "github.com/go-redis/redis/v7"
"github.com/orlangure/gnomock"
"github.com/orlangure/gnomock/preset/redis"
)
func ExamplePreset() {
vs := make(map[string]interface{})
vs["a"] = "foo"
vs["b"] = 42
vs["c"] = true
p := redis.Preset(redis.WithValues(vs))
container, _ := gnomock.Start(p)
defer func() { _ = gnomock.Stop(container) }()
addr := container.DefaultAddress()
client := redisclient.NewClient(&redisclient.Options{Addr: addr})
fmt.Println(client.Get("a").Result())
var number int
err := client.Get("b").Scan(&number)
fmt.Println(number, err)
var flag bool
err = client.Get("c").Scan(&flag)
fmt.Println(flag, err)
// Output:
// foo <nil>
// 42 <nil>
// true <nil>
}
Expand ▾
Collapse ▴
Documentation
¶
Package redis includes Redis implementation of Gnomock Preset interface.
This Preset can be passed to gnomock.Start() function to create a configured
Redis container to use in tests.
Preset creates a new Gmomock Redis preset. This preset includes a Redis
specific healthcheck function, default Redis image and port, and allows to
optionally set up initial state
Option is an optional configuration of this Gnomock preset. Use available
Options to configure the container
WithValues initializes Redis with the provided key/value pairs. These values
never expire. See go-redis/redis package for information on supported value
types
WithVersion sets image version.
type P struct {
Values map[string ]interface{} `json:"values"`
Version string `json:"version"`
}
P is a Gnomock Preset implementation for Redis storage
Image returns an image that should be pulled to create this container
Options returns a list of options to configure this container
Ports returns ports that should be used to access this container
Source Files
¶
Click to show internal directories.
Click to hide internal directories.