docker

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProjectID       = "tests"
	DefaultLabel    = "integration"
	DefaultNetwork  = "tests"
	EnvHostOverride = "HOST_OVERRIDE"
)

Variables

This section is empty.

Functions

func AwaitUntil

func AwaitUntil(duration time.Duration, resolution time.Duration, f func() error) error

func ColoredPrintf

func ColoredPrintf(msg string)

ColoredPrintf Yellow only

func Debug

func Debug(i interface{})

func FindOpenTcpPort

func FindOpenTcpPort() (string, error)

func IsEmpty

func IsEmpty(m *sync.Map) bool

IsEmpty for whatever reason they don't like to add a simple Size()/Length() method to this...

func PrintLogs

func PrintLogs(container *Container)

func PrintMap

func PrintMap(m *sync.Map) string

func ReadEnvFile

func ReadEnvFile(path string) (map[string]string, error)

func ReadFile

func ReadFile(path string) ([]string, error)

func RunProcessWithLogs

func RunProcessWithLogs(cmd *exec.Cmd, logHandler func(msg string)) error

Types

type AfterHandler

type AfterHandler func()

type BeforeHandler

type BeforeHandler func() error

type Compose

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

Compose an API to access docker-compose

func NewCompose

func NewCompose(params ComposeConfig) (*Compose, error)

func (*Compose) Down

func (c *Compose) Down() error

func (*Compose) GetContainer

func (c *Compose) GetContainer(service string) (*Container, error)

func (*Compose) Start

func (c *Compose) Start(services ...*ServiceConfig) error

func (*Compose) Stop

func (c *Compose) Stop(services ...string) error

func (*Compose) Up

func (c *Compose) Up() error

type ComposeConfig

type ComposeConfig struct {
	// Env the global config for this composes' execution
	Env *EnvironmentConfig
	// Services maps service names to their config, for those managed by this composes' execution
	Services map[string]*ServiceConfig
}

ComposeConfig config needed to get docker-compose and the testing framework going

type Container

type Container struct {
	Config        *types.Container
	ServiceConfig *ServiceConfig
	// contains filtered or unexported fields
}

Container wrapped API for docker containers

func (*Container) Exec

func (c *Container) Exec(cmd string) ([]string, error)

func (*Container) GetEndpoints

func (c *Container) GetEndpoints() (Endpoints, error)

GetEndpoints returns the public host, and map of private ports to list of public ports.

func (*Container) GetStatus

func (c *Container) GetStatus() *ContainerStatus

func (*Container) Logs

func (c *Container) Logs() (string, error)

type ContainerStatus

type ContainerStatus struct {
	Error error
	Code  ContainerStatusCode
}

type ContainerStatusCode

type ContainerStatusCode uint8
const (
	Error ContainerStatusCode = iota
	Running
	Exited
	Unhealthy
	NotReady
)

type Endpoints

type Endpoints interface {
	GetHost() string
	GetPublicPorts(privatePorts ...int) []int
}

type Environment

type Environment struct {
	// Services maps service names to their data (output of their handlers). See ServiceHandler
	Services map[string]interface{}
	// contains filtered or unexported fields
}

func StartEnvironment

func StartEnvironment(config *EnvironmentConfig, entries ...*ServiceEntry) *Environment

func (*Environment) Shutdown

func (e *Environment) Shutdown()

Shutdown MUST be used by tests' cleanup functions or there may be container leaks

func (*Environment) StartServices

func (e *Environment) StartServices(entries ...*ServiceEntry) error

func (*Environment) StopServices

func (e *Environment) StopServices(services ...string) error

type EnvironmentConfig

type EnvironmentConfig struct {
	// UpTimeout timeout for docker-compose up
	UpTimeout time.Duration
	// DownTimeout timeout for docker-compose down
	DownTimeout time.Duration
	// ComposeFilePaths the path to the compose-YAML file(s)
	ComposeFilePaths []string
	// Optional custom container label name
	Label string
	// If true it will ignore any existing containers that are running due to a previous run
	NoCleanup bool
	// If true it will not shut down the containers after the test
	NoShutdown bool
}

EnvironmentConfig global-level (i.e. for all containers) config for the testing framework

type ServiceConfig

type ServiceConfig struct {
	// Name Service name (must correspond to the name found in the compose file)
	Name string
	// EnvironmentVars optional set of key-value pairs to pass to the service (note, these must be globally unique)
	EnvironmentVars map[string]string
	// Optional custom network name
	Network string
}

ServiceConfig service/container-level config needed for docker-compose purposes

type ServiceEntry

type ServiceEntry struct {
	//Name see ServiceConfig.Name
	Name string
	// DisableShutdownLogs set to true to disable printing logs for this container on shutdown (optional)
	DisableShutdownLogs bool
	// Handler Function to extract relevant data from the service's container for the test's needs (optional, but
	// usually needed by tests/consumers)
	Handler ServiceHandler
	// Before Function to run before container startup (optional)
	Before BeforeHandler
	// Before Function to run after container shutdown (optional)
	After AfterHandler
	// EnvironmentVars env variables for the service
	EnvironmentVars map[string]string
	// Network optional network name, otherwise defaults to the Network const
	Network string
}

type ServiceHandler

type ServiceHandler func(*Container) (interface{}, error)

Jump to

Keyboard shortcuts

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