docker

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package docker is a collection of utilities to operate Docker objects in Go code tests in a simplified manner.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateContainer

func CreateContainer(ctx context.Context, image string, options *Options) (string, error)

CreateContainer creates a new Docker container and returns its id.

func CreateStartContainer

func CreateStartContainer(ctx context.Context, image string, options *Options) (string, error)

CreateStartContainer creates a new Docker container and starts it. Returns created container id.

func ExecCommand added in v0.3.0

func ExecCommand(ctx context.Context, id string, command string, buffer *bytes.Buffer) error

ExecCommand executes given shell command in Docker container.

func PullImage

func PullImage(ctx context.Context, name string) error

PullImage pulls a Docker image with the given name.

func RemoveContainer

func RemoveContainer(ctx context.Context, id string) error

RemoveContainer removes Docker container.

func StartContainer

func StartContainer(ctx context.Context, id string) error

StartContainer starts Docker container.

func StopContainer

func StopContainer(ctx context.Context, id string) error

StopContainer stops Docker container.

func StopRemoveContainer

func StopRemoveContainer(ctx context.Context, id string) error

StopRemoveContainer stops and removes Docker container.

Types

type Container

type Container interface {
	Create(ctx context.Context) error
	Start(ctx context.Context) error
	CreateStart(ctx context.Context) error
	Stop(ctx context.Context) error
	Remove(ctx context.Context) error
	StopRemove(ctx context.Context) error
	HasStarted(ctx context.Context) (bool, error)
	Exec(ctx context.Context, command string, buffer *bytes.Buffer) error
}

Container defines container methods.

func NewContainer

func NewContainer(image string) Container

NewContainer creates a new Container object.

func NewContainerWithOptions added in v0.2.0

func NewContainerWithOptions(image string, options Options) Container

NewContainerWithOptions creates a new Container object with optional attributes values specified.

type Database added in v0.3.0

type Database struct {
	Name         string
	ResetCommand string
}

Database holds database metadata.

type DatabaseContainer added in v0.3.0

type DatabaseContainer interface {
	Container
	ResetDatabase(ctx context.Context) error
}

DatabaseContainer extends Container interface with database interaction methods.

func NewDatabaseContainer added in v0.3.0

func NewDatabaseContainer(image string, db Database) DatabaseContainer

NewDatabaseContainer creates a new DatabaseContainer object.

func NewDatabaseContainerWithOptions added in v0.3.0

func NewDatabaseContainerWithOptions(image string, db Database, options Options) DatabaseContainer

NewDatabaseContainerWithOptions creates a new DatabaseContainer object with optional attributes values specified.

type Options added in v0.2.0

type Options struct {
	Name, Healthcheck                  string
	EnvironmentVariables, ExposedPorts []string
	StartTimeout                       int
}

Options holds container optional attributes values which can be set on new container object creation.

Jump to

Keyboard shortcuts

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