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 redis container, and sets the command to run the redis server using the passed config file
func WithLogLevel ¶
func WithLogLevel(level LogLevel) testcontainers.CustomizeRequestOption
WithLogLevel sets the log level for the redis server process See "RedisModule_Log" for more information.
func WithSnapshotting ¶
WithSnapshotting sets the snapshotting configuration for the redis server process. You can configure Redis to have it save the dataset every N seconds if there are at least M changes in the dataset. This method allows Redis to benefit from copy-on-write semantics. See 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.37.0
type Option func(*options) error
Option is an option for the Redpanda container.
type RedisContainer ¶
type RedisContainer struct { testcontainers.Container // contains filtered or unexported fields }
func Run ¶ added in v0.32.0
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error)
Run creates an instance of the Redis container type
Example ¶
// runRedisContainer { ctx := context.Background() redisContainer, err := tcredis.Run(ctx, "redis:7", tcredis.WithSnapshotting(10, 1), tcredis.WithLogLevel(tcredis.LogLevelVerbose), tcredis.WithConfigFile(filepath.Join("testdata", "redis7.conf")), ) defer func() { if err := testcontainers.TerminateContainer(redisContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } // } state, err := redisContainer.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() redisContainer, err := tcredis.Run(ctx, "redis:7", tcredis.WithSnapshotting(10, 1), tcredis.WithLogLevel(tcredis.LogLevelVerbose), tcredis.WithTLS(), ) defer func() { if err := testcontainers.TerminateContainer(redisContainer); err != nil { log.Printf("failed to terminate container: %s", err) } }() if err != nil { log.Printf("failed to start container: %s", err) return } if redisContainer.TLSConfig() == nil { log.Println("TLS is not enabled") return } uri, err := redisContainer.ConnectionString(ctx) if err != nil { log.Printf("failed to get connection string: %s", err) return } // You will likely want to wrap your Redis 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 := redis.ParseURL(uri) if err != nil { log.Printf("failed to parse connection string: %s", err) return } options.TLSConfig = redisContainer.TLSConfig() client := redis.NewClient(options) defer func(ctx context.Context, client *redis.Client) { err := flushRedis(ctx, *client) if err != nil { log.Printf("failed to flush redis: %s", err) } }(ctx, client) pong, err := client.Ping(ctx).Result() if err != nil { log.Printf("failed to ping redis: %s", err) return } fmt.Println(pong)
Output: PONG
func RunContainer
deprecated
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error)
Deprecated: use Run instead RunContainer creates an instance of the Redis container type
func (*RedisContainer) ConnectionString ¶
func (c *RedisContainer) ConnectionString(ctx context.Context) (string, error)
ConnectionString returns the connection string for the Redis container. It uses the default 6379 port.
func (*RedisContainer) TLSConfig ¶ added in v0.37.0
func (c *RedisContainer) TLSConfig() *tls.Config
TLSConfig returns the TLS configuration for the Redis container, nil if TLS is not enabled.