Documentation
¶
Index ¶
- func ConvertTestName(testName string) string
- func NewDockerCli() (command.Cli, error)
- func WaitForStack(ctx context.Context, t *testing.T, compose api.Compose, projectName string, ...) ([]api.ContainerSummary, error)
- type ComposeOption
- func WithCustomLabel(labels map[string]string) ComposeOption
- func WithFile(filePath string) ComposeOption
- func WithName(name string) ComposeOption
- func WithNoWait() ComposeOption
- func WithPruneImages() ComposeOption
- func WithWaitTimeout(timeout time.Duration) ComposeOption
- func WithYAML(yaml string) ComposeOption
- type ComposeStack
- func (s *ComposeStack) ContainerLogs(ctx context.Context, t *testing.T, serviceName string, since time.Time) string
- func (s *ComposeStack) Endpoint(ctx context.Context, t *testing.T, serviceName, containerPort string) string
- func (s *ComposeStack) Exec(ctx context.Context, t *testing.T, serviceName string, cmd []string) (int, io.Reader)
- func (s *ComposeStack) MappedPort(ctx context.Context, t *testing.T, serviceName, containerPort string) string
- func (s *ComposeStack) ServiceContainerID(ctx context.Context, t *testing.T, serviceName string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertTestName ¶
ConvertTestName converts a test name to a format suitable for stack names or similar uses. e.g. "TestHandlerData_ProjectApiHandler/Restart_Project_-_Invalid_Method" should be converted to "testhandlerdata-projectapihandler_restart-project-invalid-method-1234". Returns a string that is lowercase, with non-alphanumeric characters replaced by hyphens, and truncated to 40 characters if necessary, with a random number appended to ensure uniqueness.
func NewDockerCli ¶ added in v0.72.0
NewDockerCli creates a docker CLI for test use.
Types ¶
type ComposeOption ¶ added in v0.72.0
type ComposeOption func(*composeOptions)
ComposeOption configures a ComposeUp call.
func WithCustomLabel ¶ added in v0.78.0
func WithCustomLabel(labels map[string]string) ComposeOption
func WithFile ¶ added in v0.72.0
func WithFile(filePath string) ComposeOption
WithFile sets the compose source to a file path.
func WithName ¶ added in v0.72.0
func WithName(name string) ComposeOption
WithName sets a custom stack name. If not set, the stack name defaults to a sanitized version of the test name.
func WithNoWait ¶ added in v0.72.2
func WithNoWait() ComposeOption
WithNoWait disables waiting for containers to be healthy after starting the stack.
func WithPruneImages ¶ added in v0.72.0
func WithPruneImages() ComposeOption
WithPruneImages removes all images when the stack is taken down during cleanup.
func WithWaitTimeout ¶ added in v0.72.2
func WithWaitTimeout(timeout time.Duration) ComposeOption
WithWaitTimeout sets the maximum time to wait for containers to be healthy in ComposeUp. Default is 30 seconds.
func WithYAML ¶ added in v0.72.0
func WithYAML(yaml string) ComposeOption
WithYAML sets the compose source to an inline YAML string.
type ComposeStack ¶ added in v0.72.0
type ComposeStack struct {
Name string
Service api.Compose
DockerCli command.Cli
Client client.APIClient
}
ComposeStack represents a running compose stack for tests.
func ComposeUp ¶ added in v0.72.0
func ComposeUp(ctx context.Context, t *testing.T, opts ...ComposeOption) *ComposeStack
ComposeUp deploys a compose stack and registers automatic cleanup via t.Cleanup. Use WithYAML or WithFile to set the compose source, and WithName to set a custom stack name.
func (*ComposeStack) ContainerLogs ¶ added in v0.77.0
func (s *ComposeStack) ContainerLogs(ctx context.Context, t *testing.T, serviceName string, since time.Time) string
ContainerLogs gets the logs for a container, includes stdout and stderr.
func (*ComposeStack) Endpoint ¶ added in v0.72.0
func (s *ComposeStack) Endpoint(ctx context.Context, t *testing.T, serviceName, containerPort string) string
Endpoint returns host:port for a service's container port. containerPort can be "80", "80/tcp", or "80/udp". If no protocol is specified, "tcp" is assumed.
func (*ComposeStack) Exec ¶ added in v0.72.0
func (s *ComposeStack) Exec(ctx context.Context, t *testing.T, serviceName string, cmd []string) (int, io.Reader)
Exec runs a command inside a container of the given service and returns exit code + output reader. The output reader contains multiplexed stdout/stderr from the Docker API.
func (*ComposeStack) MappedPort ¶ added in v0.72.0
func (s *ComposeStack) MappedPort(ctx context.Context, t *testing.T, serviceName, containerPort string) string
MappedPort returns the host port mapped to a container's port for a given service. containerPort can be "80", "80/tcp", or "80/udp". If no protocol is specified, "tcp" is assumed.
func (*ComposeStack) ServiceContainerID ¶ added in v0.72.0
func (s *ComposeStack) ServiceContainerID(ctx context.Context, t *testing.T, serviceName string) string
ServiceContainerID returns the container ID for a service in the stack.