testutil

package
v0.0.0-...-2ca7562 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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
	// Blocks port on host
	BlockPort(service string, port int) error
	// Unblocks port on host
	UnBlockPort(service string, port int) 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)
}

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) BlockPort

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

BlockPort blocks port for host

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) UnBlockPort

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

UnBlockPort removes blocking rules for port on host

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