Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConfigFile ¶
func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption
WithConfigFile sets the config file to be used for the valkey container, and sets the command to run the valkey server using the passed config file
func WithLogLevel ¶
func WithLogLevel(level LogLevel) testcontainers.CustomizeRequestOption
WithLogLevel sets the log level for the valkey server process See https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_log for more information.
func WithSnapshotting ¶
func WithSnapshotting(seconds int, changedKeys int) testcontainers.CustomizeRequestOption
WithSnapshotting sets the snapshotting configuration for the valkey server process. You can configure Valkey to have it save the dataset every N seconds if there are at least M changes in the dataset. This method allows Valkey to benefit from copy-on-write semantics. See https://redis.io/docs/management/persistence/#snapshotting for more information.
Types ¶
type LogLevel ¶
type LogLevel string
const ( // LogLevelDebug is the debug log level LogLevelDebug LogLevel = "debug" // LogLevelVerbose is the verbose log level LogLevelVerbose LogLevel = "verbose" // LogLevelNotice is the notice log level LogLevelNotice LogLevel = "notice" // LogLevelWarning is the warning log level LogLevelWarning LogLevel = "warning" )
type Option ¶ added in v0.38.0
type Option func(*options) error
Option is an option for the Redpanda container.
func WithTLS ¶ added in v0.38.0
func WithTLS() Option
WithTLS sets the TLS configuration for the redis container, setting the 6380/tcp port to listen on for TLS connections and using a secure URL (rediss://).
func (Option) Customize ¶ added in v0.38.0
func (o Option) Customize(*testcontainers.GenericContainerRequest) error
Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.
type ValkeyContainer ¶
type ValkeyContainer struct {
testcontainers.Container
// contains filtered or unexported fields
}
ValkeyContainer represents the Valkey container type used in the module
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ValkeyContainer, error)
Run creates an instance of the Valkey container type
Example ¶
package main
import (
"context"
"fmt"
"log"
"path/filepath"
"github.com/testcontainers/testcontainers-go"
tcvalkey "github.com/testcontainers/testcontainers-go/modules/valkey"
)
func main() {
// runValkeyContainer {
ctx := context.Background()
valkeyContainer, err := tcvalkey.Run(ctx,
"valkey/valkey:7.2.5",
tcvalkey.WithSnapshotting(10, 1),
tcvalkey.WithLogLevel(tcvalkey.LogLevelVerbose),
tcvalkey.WithConfigFile(filepath.Join("testdata", "valkey7.conf")),
)
defer func() {
if err := testcontainers.TerminateContainer(valkeyContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := valkeyContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
}
Output: true
Example (WithTLS) ¶
ctx := context.Background()
valkeyContainer, err := tcvalkey.Run(ctx,
"valkey/valkey:7.2.5",
tcvalkey.WithSnapshotting(10, 1),
tcvalkey.WithLogLevel(tcvalkey.LogLevelVerbose),
tcvalkey.WithTLS(),
)
defer func() {
if err := testcontainers.TerminateContainer(valkeyContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
if valkeyContainer.TLSConfig() == nil {
log.Println("TLS is not enabled")
return
}
uri, err := valkeyContainer.ConnectionString(ctx)
if err != nil {
log.Printf("failed to get connection string: %s", err)
return
}
// You will likely want to wrap your Valkey package of choice in an
// interface to aid in unit testing and limit lock-in throughout your
// codebase but that's out of scope for this example
options, err := valkey.ParseURL(uri)
if err != nil {
log.Printf("failed to parse connection string: %s", err)
return
}
options.TLSConfig = valkeyContainer.TLSConfig()
client, err := valkey.NewClient(options)
if err != nil {
log.Printf("failed to create valkey client: %s", err)
return
}
defer func() {
err := flushValkey(ctx, client)
if err != nil {
log.Printf("failed to flush valkey: %s", err)
}
}()
resp := client.Do(ctx, client.B().Ping().Build().Pin())
fmt.Println(resp.String())
Output: {"Message":{"Value":"PONG","Type":"simple string"}}
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ValkeyContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Valkey container type
func (*ValkeyContainer) ConnectionString ¶
func (c *ValkeyContainer) ConnectionString(ctx context.Context) (string, error)
ConnectionString returns the connection string for the Valkey container
func (*ValkeyContainer) TLSConfig ¶ added in v0.38.0
func (c *ValkeyContainer) TLSConfig() *tls.Config
TLSConfig returns the TLS configuration for the Valkey container, nil if TLS is not enabled.