Documentation
¶
Overview ¶
Package redis includes Redis implementation of Gnomock Preset interface. This Preset can be passed to gnomock.StartPreset function to create a configured Redis container to use in tests
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Preset ¶
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
Example ¶
package main
import (
"fmt"
"github.com/go-redis/redis/v7"
"github.com/orlangure/gnomock"
mockredis "github.com/orlangure/gnomock-redis"
)
func main() {
vs := make(map[string]interface{})
vs["a"] = "foo"
vs["b"] = 42
vs["c"] = true
p := mockredis.Preset(mockredis.WithValues(vs))
container, _ := gnomock.Start(p)
defer func() { _ = gnomock.Stop(container) }()
addr := container.DefaultAddress()
client := redis.NewClient(&redis.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>
Types ¶
type Option ¶
type Option func(*P)
Option is an optional configuration of this Gnomock preset. Use available Options to configure the container
func WithValues ¶
WithValues initializes Redis with the provided key/value pairs. These values never expire. See go-redis/redis package for information on supported value types
type P ¶ added in v0.3.1
type P struct {
Values map[string]interface{} `json:"values"`
}
P is a Gnomock Preset implementation for Redis storage
func (*P) Image ¶ added in v0.3.1
Image returns an image that should be pulled to create this container
func (*P) Ports ¶ added in v0.3.1
func (r *P) Ports() gnomock.NamedPorts
Ports returns ports that should be used to access this container