Documentation
¶
Index ¶
- Constants
- type Container
- type ContainerProvider
- type ContainerRequest
- type DeprecatedContainer
- type DockerContainer
- func (c *DockerContainer) Endpoint(ctx context.Context, proto string) (string, error)
- func (c *DockerContainer) GetContainerID() string
- func (c *DockerContainer) GetHostEndpoint(ctx context.Context, port string) (string, string, error)
- func (c *DockerContainer) GetIPAddress(ctx context.Context) (string, error)
- func (c *DockerContainer) Host(ctx context.Context) (string, error)
- func (c *DockerContainer) LivenessCheckPorts(ctx context.Context) (nat.PortSet, error)
- func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error)
- func (c *DockerContainer) MappedPort(ctx context.Context, port nat.Port) (nat.Port, error)
- func (c *DockerContainer) Name(ctx context.Context) (string, error)
- func (c *DockerContainer) PortEndpoint(ctx context.Context, port nat.Port, proto string) (string, error)
- func (c *DockerContainer) Ports(ctx context.Context) (nat.PortMap, error)
- func (c *DockerContainer) SessionID() string
- func (c *DockerContainer) Start(ctx context.Context) error
- func (c *DockerContainer) Terminate(ctx context.Context) error
- type DockerProvider
- type GenericContainerRequest
- type ProviderType
- type Reaper
- type ReaperProvider
- type RequestContainer
Constants ¶
const ( TestcontainerLabel = "org.testcontainers.golang" TestcontainerLabelSessionID = TestcontainerLabel + ".sessionId" TestcontainerLabelIsReaper = TestcontainerLabel + ".reaper" ReaperDefaultImage = "quay.io/testcontainers/ryuk:0.2.2" )
TestcontainerLabel is used as a base for docker labels
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container interface {
GetContainerID() string // get the container id from the provider
Endpoint(context.Context, string) (string, error) // get proto://ip:port string for the first exposed port
PortEndpoint(context.Context, nat.Port, string) (string, error) // get proto://ip:port string for the given exposed port
Host(context.Context) (string, error) // get host where the container port is exposed
MappedPort(context.Context, nat.Port) (nat.Port, error) // get externally mapped port for a container port
Ports(context.Context) (nat.PortMap, error) // get all exposed ports
SessionID() string // get session id
Start(context.Context) error // start the container
Terminate(context.Context) error // terminate the container
Logs(context.Context) (io.ReadCloser, error) // Get logs of the container
Name(context.Context) (string, error) // get container name
}
Container allows getting info about and controlling a single container instance
func GenericContainer ¶
func GenericContainer(ctx context.Context, req GenericContainerRequest) (Container, error)
GenericContainer creates a generic container with parameters
type ContainerProvider ¶
type ContainerProvider interface {
CreateContainer(context.Context, ContainerRequest) (Container, error) // create a container without starting it
RunContainer(context.Context, ContainerRequest) (Container, error) // create a container and start it
}
ContainerProvider allows the creation of containers on an arbitrary system
type ContainerRequest ¶
type ContainerRequest struct {
Image string
Env map[string]string
ExposedPorts []string // allow specifying protocol info
Cmd string
Labels map[string]string
BindMounts map[string]string
RegistryCred string
WaitingFor wait.Strategy
Name string // for specifying container name
Privileged bool // for starting privileged container
SkipReaper bool // indicates whether we skip setting up a reaper for this
}
ContainerRequest represents the parameters used to get a running container
type DeprecatedContainer ¶
type DeprecatedContainer interface {
GetHostEndpoint(ctx context.Context, port string) (string, string, error)
GetIPAddress(ctx context.Context) (string, error)
LivenessCheckPorts(ctx context.Context) (nat.PortSet, error)
Terminate(ctx context.Context) error
}
DeprecatedContainer shows methods that were supported before, but are now deprecated Deprecated: Use Container
func RunContainer ¶
func RunContainer(ctx context.Context, containerImage string, input RequestContainer) (DeprecatedContainer, error)
RunContainer takes a RequestContainer as input and it runs a container via the docker sdk Deprecated: Use GenericContainer()
type DockerContainer ¶
type DockerContainer struct {
// Container ID from Docker
ID string
WaitingFor wait.Strategy
// contains filtered or unexported fields
}
DockerContainer represents a container started using Docker
func (*DockerContainer) Endpoint ¶
Endpoint gets proto://host:port string for the first exposed port Will returns just host:port if proto is ""
func (*DockerContainer) GetContainerID ¶
func (c *DockerContainer) GetContainerID() string
func (*DockerContainer) GetHostEndpoint ¶
GetHostEndpoint is deprecated and kept for backwards compat Deprecated: Use Endpoint()
func (*DockerContainer) GetIPAddress ¶
func (c *DockerContainer) GetIPAddress(ctx context.Context) (string, error)
GetIPAddress is deprecated and kept for backwards compat Deprecated: Use IPAddress()
func (*DockerContainer) Host ¶
func (c *DockerContainer) Host(ctx context.Context) (string, error)
Host gets host (ip or name) of the docker daemon where the container port is exposed Warning: this is based on your Docker host setting. Will fail if using an SSH tunnel You can use the "TC_HOST" env variable to set this yourself
func (*DockerContainer) LivenessCheckPorts ¶
LivenessCheckPorts is deprecated and kept for backwards compat Deprecated: Use Ports()
func (*DockerContainer) Logs ¶
func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error)
Logs will fetch both STDOUT and STDERR from the current container. Returns a ReadCloser and leaves it up to the caller to extract what it wants.
func (*DockerContainer) MappedPort ¶
MappedPort gets externally mapped port for a container port
func (*DockerContainer) Name ¶ added in v0.0.5
func (c *DockerContainer) Name(ctx context.Context) (string, error)
Name gets the name of the container.
func (*DockerContainer) PortEndpoint ¶
func (c *DockerContainer) PortEndpoint(ctx context.Context, port nat.Port, proto string) (string, error)
PortEndpoint gets proto://host:port string for the given exposed port Will returns just host:port if proto is ""
func (*DockerContainer) SessionID ¶
func (c *DockerContainer) SessionID() string
SessionID gets the current session id
type DockerProvider ¶
type DockerProvider struct {
// contains filtered or unexported fields
}
DockerProvider implements the ContainerProvider interface
func NewDockerProvider ¶
func NewDockerProvider() (*DockerProvider, error)
NewDockerProvider creates a Docker provider with the EnvClient
func (*DockerProvider) CreateContainer ¶
func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerRequest) (Container, error)
CreateContainer fulfills a request for a container without starting it
func (*DockerProvider) RunContainer ¶
func (p *DockerProvider) RunContainer(ctx context.Context, req ContainerRequest) (Container, error)
RunContainer takes a RequestContainer as input and it runs a container via the docker sdk
type GenericContainerRequest ¶
type GenericContainerRequest struct {
ContainerRequest // embedded request for provider
Started bool // whether to auto-start the container
ProviderType ProviderType // which provider to use, Docker if empty
}
GenericContainerRequest represents parameters to a generic container
type ProviderType ¶
type ProviderType int
ProviderType is an enum for the possible providers
const (
ProviderDocker ProviderType = iota // Docker is default = 0
)
possible provider types
func (ProviderType) GetProvider ¶
func (t ProviderType) GetProvider() (ContainerProvider, error)
GetProvider provides the provider implementation for a certain type
type Reaper ¶
type Reaper struct {
Provider ReaperProvider
SessionID string
Endpoint string
}
Reaper is used to start a sidecar container that cleans up resources
func NewReaper ¶
NewReaper creates a Reaper with a sessionID to identify containers and a provider to use
type ReaperProvider ¶
type ReaperProvider interface {
RunContainer(ctx context.Context, req ContainerRequest) (Container, error)
}
ReaperProvider represents a provider for the reaper to run itself with The ContainerProvider interface should usually satisfy this as well, so it is pluggable
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
bigtable
module
|
|
|
cockroachdb
module
|
|
|
consul
module
|
|
|
datastore
module
|
|
|
firestore
module
|
|
|
mongodb
module
|
|
|
mysql
module
|
|
|
nats
module
|
|
|
nginx
module
|
|
|
postgres
module
|
|
|
pubsub
module
|
|
|
pulsar
module
|
|
|
redis
module
|
|
|
spanner
module
|
|
|
toxiproxy
module
|
|
|
modulegen
module
|
|
|
modules
|
|
|
aerospike
module
|
|
|
arangodb
module
|
|
|
artemis
module
|
|
|
azure
module
|
|
|
azurite
module
|
|
|
cassandra
module
|
|
|
chroma
module
|
|
|
clickhouse
module
|
|
|
cockroachdb
module
|
|
|
compose
module
|
|
|
consul
module
|
|
|
couchbase
module
|
|
|
databend
module
|
|
|
dind
module
|
|
|
dockermcpgateway
module
|
|
|
dockermodelrunner
module
|
|
|
dolt
module
|
|
|
dynamodb
module
|
|
|
elasticsearch
module
|
|
|
etcd
module
|
|
|
forgejo
module
|
|
|
gcloud
module
|
|
|
grafana-lgtm
module
|
|
|
inbucket
module
|
|
|
influxdb
module
|
|
|
k3s
module
|
|
|
k6
module
|
|
|
kafka
module
|
|
|
localstack
module
|
|
|
mariadb
module
|
|
|
meilisearch
module
|
|
|
memcached
module
|
|
|
milvus
module
|
|
|
minio
module
|
|
|
mockserver
module
|
|
|
mongodb
module
|
|
|
mssql
module
|
|
|
mysql
module
|
|
|
nats
module
|
|
|
nebulagraph
module
|
|
|
neo4j
module
|
|
|
ollama
module
|
|
|
openfga
module
|
|
|
openldap
module
|
|
|
opensearch
module
|
|
|
pinecone
module
|
|
|
postgres
module
|
|
|
pulsar
module
|
|
|
qdrant
module
|
|
|
rabbitmq
module
|
|
|
redis
module
|
|
|
redpanda
module
|
|
|
registry
module
|
|
|
scylladb
module
|
|
|
socat
module
|
|
|
solace
module
|
|
|
surrealdb
module
|
|
|
tidb
module
|
|
|
toxiproxy
module
|
|
|
valkey
module
|
|
|
vault
module
|
|
|
vearch
module
|
|
|
weaviate
module
|
|
|
yugabytedb
module
|
|
|
usage-metrics
module
|
|