utils

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package utils provides utilities supporting the smoke tests.

Package utils contains higher-level (e.g., integration) tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerExternalHost

func ContainerExternalHost(ctx context.Context, container testcontainers.Container, port string) (*url.URL, error)

ContainerExternalHost gets the external host of for a specific container based on what port testcontainers forwarded to on the host machine.

This is only needed for external communications between application and the container. This is NOT needed for container to container interactions on the same network

func ContainerHasLogMessage added in v1.2.0

func ContainerHasLogMessage(
	ctx context.Context,
	input *ContainerHasLogMessageInput,
) (bool, error)

ContainerHasLogMessage checks the container log buffer for a specific string message

func ContainerWaitForLog

func ContainerWaitForLog(ctx context.Context, input *WaitForLogInput) error

ContainerWaitForLog polls the logs of the container to see if a `log` message exists. If the timeout is exceeded, an error returns.

func WaitForCondition

func WaitForCondition(
	ctx context.Context,
	timeout time.Duration,
	poll time.Duration,
	condition func() (bool, error),
) error

WaitForCondition waits for a specific condition to return true.

Types

type ContainerHasLogMessageInput added in v1.2.0

type ContainerHasLogMessageInput struct {
	Container  *testcontainers.Container
	Log        string
	AllowError bool
	N          int
}

type LogCapture

type LogCapture struct {
	Lines []string
	// contains filtered or unexported fields
}

func NewLogCapture

func NewLogCapture(logger *logrus.Logger) *LogCapture

NewLogCapture sets up plain text logging to be captured for testing purposes

func NewLogCaptureWithCurrentFormatter

func NewLogCaptureWithCurrentFormatter(logger *logrus.Logger) *LogCapture

NewLogCaptureWithCurrentFormatter sets up capture with current formatter

func (*LogCapture) Clear

func (l *LogCapture) Clear()

Clear clears captured lines

func (*LogCapture) Extract

func (l *LogCapture) Extract(index int, key string) string

Extract looks for a key=value pair for line at given index, returning the value or empty if not found. This is possible because we log using plain text logging.

func (*LogCapture) Len

func (l *LogCapture) Len() int

Len returns number of log lines captured

func (*LogCapture) Write

func (l *LogCapture) Write(p []byte) (n int, err error)

Write echos line to console and captures same line

type MockRoundTripper

type MockRoundTripper struct {
	Responses map[string][]*http.Response
	Errors    map[string][]error
}

func NewHTTPMock

func NewHTTPMock() *MockRoundTripper

func (*MockRoundTripper) Expect

func (m *MockRoundTripper) Expect(method string, body string, status int, err error)

func (*MockRoundTripper) HTTPClient

func (m *MockRoundTripper) HTTPClient() *http.Client

func (*MockRoundTripper) RoundTrip

func (m *MockRoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

type WaitForLogInput

type WaitForLogInput struct {
	Container  *testcontainers.Container
	Log        string
	Timeout    time.Duration
	Poll       time.Duration
	AllowError bool // if errors should not fail the search
	N          int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL