testutil

package
v0.0.0-...-0caea15 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: PostgreSQL Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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
	// Trears all containers/VMs dowwn
	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
	// Detachs container/VM from network
	DetachFromNet(service string) error
	// Attachs container/VM to network
	AttachToNet(service string) error
	// Executes command inside container/VM with given timeout.
	// Returns command retcode and output (stdoud 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 (stdoud 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 distguish docker container and networks from different runs

func (*DockerComposer) AttachToNet

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

AttachToNet attachs container to 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) Down

func (dc *DockerComposer) Down() error

Down trears all containers/VMs dowwn

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 continer 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