testutil

package
v0.0.0-...-8eac4e3 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Consistently

func Consistently(code func() bool, duration, sleep time.Duration) bool

Consistently checks that code succeeds for the whole duration, including a final check at the deadline.

func Eventually

func Eventually(code func() bool, timeout, sleep time.Duration) bool

Eventually checks code until it succeeds or the timeout expires. Unlike Retry, it always performs a final check at the deadline.

func GetFreePort

func GetFreePort() (string, error)

GetFreePort returns a random tcp port available for binding (at the moment of call)

func MatchContext

func MatchContext(t *testing.T, ctx context.Context) (context.Context, gomock.Matcher)

func NewUUID

func NewUUID(t *testing.T) uuid.UUID

func NewUUIDStr

func NewUUIDStr(t *testing.T) string

func Retry

func Retry(code func() bool, timeout, sleep time.Duration)

nolint: unparam

Types

type Composer

type Composer interface {
	// Brings all containers/VMs up according to config
	Up(env []string) error
	// Tears all containers/VMs down
	Down() error
	// Returns names/ids of running containers
	Services() []string
	// Returns real exposed addr (ip:port) for given service/port
	GetAddr(service string, port int) (string, error)
	// Returns internal ip address of given service
	GetIP(service string) (string, error)
	// Stops container/VM
	Stop(service string) error
	// Starts container/VM
	Start(service string) error
	// Detaches container/VM from network
	DetachFromNet(service string) error
	// Attaches container/VM to network
	AttachToNet(service string) error
	// Detaches container/VM from user network
	DetachFromUserNet(service string) error
	// Attaches container/VM to user network
	AttachToUserNet(service string) error
	// Executes command inside container/VM with given timeout.
	// Returns command retcode and output (stdout and stderr are mixed)
	RunCommand(service, cmd string, timeout time.Duration) (retcode int, output string, err error)
	RunCommandAtHosts(cmd, hostsSubstring string, timeout time.Duration) error
	// Executes command inside container/VM with given timeout.
	// Returns command retcode and output (stdout and stderr are mixed)
	RunAsyncCommand(service, cmd string) error
	// Returns content of the file from container by path
	GetFile(service, path string) (io.ReadCloser, error)
	// CheckIfFileExist Checks if file exists
	CheckIfFileExist(service, path string) (bool, error)
}

Composer manipulate images/vm's during integration tests

type DockerComposer

type DockerComposer struct {
	// contains filtered or unexported fields
}

DockerComposer is a Composer implementation based on docker and docker compose

func NewDockerComposer

func NewDockerComposer(project, config string) (*DockerComposer, error)

NewDockerComposer returns DockerComposer instance for specified compose file Parameter project specify prefix to distinguish docker container and networks from different runs

func (*DockerComposer) AttachToNet

func (dc *DockerComposer) AttachToNet(service string) error

AttachToNet attaches container to network

func (*DockerComposer) AttachToUserNet

func (dc *DockerComposer) AttachToUserNet(service string) error

AttachToUserNet attaches container to user network

func (*DockerComposer) CheckIfFileExist

func (dc *DockerComposer) CheckIfFileExist(service, path string) (bool, error)

CheckIfFileExist Checks if file exists

func (*DockerComposer) DetachFromNet

func (dc *DockerComposer) DetachFromNet(service string) error

DetachFromNet detaches container from network

func (*DockerComposer) DetachFromUserNet

func (dc *DockerComposer) DetachFromUserNet(service string) error

DetachFromUserNet detaches container from user network

func (*DockerComposer) Down

func (dc *DockerComposer) Down() error

Down tears all containers/VMs down

func (*DockerComposer) GetAddr

func (dc *DockerComposer) GetAddr(service string, port int) (string, error)

GetAddr returns real exposed addr (ip:port) for given service/port

func (*DockerComposer) GetFile

func (dc *DockerComposer) GetFile(service, path string) (io.ReadCloser, error)

GetFile returns content of the fail from container by path

func (*DockerComposer) GetIP

func (dc *DockerComposer) GetIP(service string) (string, error)

GetIP returns internal ip address of given service

func (*DockerComposer) RunAsyncCommand

func (dc *DockerComposer) RunAsyncCommand(service string, cmd string) error

RunAsyncCommand executes command inside container/VM without waiting for termination.

func (*DockerComposer) RunCommand

func (dc *DockerComposer) RunCommand(service string, cmd string, timeout time.Duration) (retcode int, out string, err error)

RunCommand executes command inside container/VM with given timeout.

func (*DockerComposer) RunCommandAtHosts

func (dc *DockerComposer) RunCommandAtHosts(cmd, hostSubstring string, timeout time.Duration) error

func (*DockerComposer) Services

func (dc *DockerComposer) Services() []string

Services returns names/ids of running containers

func (*DockerComposer) Start

func (dc *DockerComposer) Start(service string) error

Start starts container by service name

func (*DockerComposer) Stop

func (dc *DockerComposer) Stop(service string) error

Stop stops container by service name

func (*DockerComposer) Up

func (dc *DockerComposer) Up(env []string) error

Up brings all containers up according to config

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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