Documentation
¶
Overview ¶
Package gronats provides NATS integration for testing using the groat framework. It allows easy setup and usage of NATS server in Docker containers for integration tests.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New[T any](options ...Option) integration.Bootstrap[T]
New creates a new factory method for build NATS integration container with the given options.
Types ¶
type Container ¶
type Container[T any] struct { // contains filtered or unexported fields }
Container represents a NATS integration container for testing. Provides NATS server instance and manages its lifecycle during tests.
type NATsContainer ¶
type NATsContainer interface {
ConnectionString(ctx context.Context) (string, error)
Terminate(ctx context.Context, opts ...testcontainers.TerminateOption) error
}
type Option ¶
type Option func(*config)
Option represents a configuration option for configure the NATS container construction. Used to customize container behavior and specify dependency injection.
func WithContainerImage ¶
func WithContainerImage(img string) Option
WithContainerImage sets the Docker image to use for the NATS container. image is the Docker image name and tag (e.g., "nats:2.6").
func WithImageEnvValue ¶
func WithImageEnvValue(env string) Option
WithImageEnvValue sets the environment variable name for the Docker image. envVar is the environment variable name that contains the image specification. By default, GROAT_I9N_NATS_IMAGE.
func WithInjectLabel ¶
func WithInjectLabel(label string) Option
WithInjectLabel sets the label for NATS client dependency injection. label is the label tag name in Deps structure, used in groat for dependency identification. By default, the value is "nats"
example:
type Deps structure {
NATSClient *nats.Conn `groat:"nats"`
}
func WithInjectLabelCasePrefix ¶
func WithInjectLabelCasePrefix(label string) Option
WithInjectLabelCasePrefix sets the label for prefix injection. Label is the label name used for prefix dependency injection. Prefix is a string like "$num_", where $num is a numerical value for a test case. By default, the value is "nats.prefix"
example:
type Deps structure {
CasePrefix string `groat:"nats.prefix"`
}
func WithInjectLabelDSN ¶
func WithInjectLabelDSN(label string) Option
WithInjectLabelDSN sets the label for connection string injection. Label is the label name used for connection string dependency injection. By default, the value is "nats.config"
example:
type Deps structure {
DSN string `groat:"nats.config"`
}
func WithNameSpaceLabel ¶ added in v0.0.2
func WithNameSpaceLabel(label string) Option