enginetest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package enginetest provides an in-memory engine.Engine and a contract suite that keeps it honest: the same suite runs against the fake and against a real daemon.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunContract

func RunContract(t *testing.T, e engine.Engine, s Seeder)

RunContract checks the behavior every Engine implementation must share. Resources are labelled with a per-run marker, so the suite is safe to run against a shared daemon.

Types

type Fake

type Fake struct {

	// FailOn makes the named method ("CreateVolume", "ListContainers", ...) return the error.
	FailOn map[string]error
	// OnCall, if set, runs before every method; a non-nil result is returned as its error.
	OnCall func(method string) error
	// RunExit is the exit code RunContainer reports.
	RunExit int
	// CreateVolumeHidesLabels makes CreateVolume answer for an existing volume without its
	// labels, as Docker may right after it started.
	CreateVolumeHidesLabels bool
	// contains filtered or unexported fields
}

Fake is an in-memory Engine. The zero value is not usable, call New.

func Load

func Load(path string) (*Fake, error)

Load reads a fake persisted with Save, or returns an empty one if path does not exist.

func New

func New() *Fake

New returns an empty fake daemon.

func (*Fake) AddContainer

func (f *Fake) AddContainer(c engine.Container) string

AddContainer adds a container, as Compose would, and returns its id.

func (*Fake) AddImage

func (f *Fake) AddImage(ref string)

AddImage marks an image as present.

func (*Fake) AddNetwork

func (f *Fake) AddNetwork(n engine.Network) string

AddNetwork adds a network and returns its id.

func (*Fake) ConnectNetwork

func (f *Fake) ConnectNetwork(_ context.Context, network, container string, aliases []string) error

func (*Fake) ContainerStats added in v0.2.0

func (f *Fake) ContainerStats(_ context.Context, id string) (engine.Stats, error)

ContainerStats reports what SetStats set, else a container that uses nothing.

func (*Fake) CopyToContainer

func (f *Fake) CopyToContainer(_ context.Context, id string, files map[string][]byte) error

func (*Fake) CreateContainer

func (f *Fake) CreateContainer(_ context.Context, spec engine.ContainerSpec) (string, error)

func (*Fake) CreateNetwork

func (f *Fake) CreateNetwork(_ context.Context, name string, labels map[string]string) (engine.Network, error)

func (*Fake) CreateVolume

func (f *Fake) CreateVolume(_ context.Context, name string, labels map[string]string) (engine.Volume, error)

func (*Fake) DisconnectNetwork

func (f *Fake) DisconnectNetwork(_ context.Context, network, container string) error

func (*Fake) Emit

func (f *Fake) Emit(id, action string, attrs map[string]string)

Emit sends an event about a container to the Events streams, as Docker would; for events the fake does not make itself, such as "health_status: healthy".

func (*Fake) Events

func (f *Fake) Events(ctx context.Context, labelFilters ...string) (<-chan engine.Event, <-chan error)

func (*Fake) Files

func (f *Fake) Files(id string) map[string][]byte

Files returns what was copied into a container.

func (*Fake) ImageExists

func (f *Fake) ImageExists(_ context.Context, ref string) (bool, error)

func (*Fake) Info

func (f *Fake) Info(context.Context) (engine.Info, error)

func (*Fake) InspectContainer

func (f *Fake) InspectContainer(_ context.Context, id string) (engine.ContainerDetails, bool, error)

func (*Fake) InspectVolume

func (f *Fake) InspectVolume(_ context.Context, name string) (engine.Volume, bool, error)

func (*Fake) ListContainers

func (f *Fake) ListContainers(_ context.Context, labelFilters ...string) ([]engine.Container, error)

func (*Fake) ListNetworks

func (f *Fake) ListNetworks(_ context.Context, labelFilters ...string) ([]engine.Network, error)

func (*Fake) ListVolumes

func (f *Fake) ListVolumes(_ context.Context, labelFilters ...string) ([]engine.Volume, error)

func (*Fake) NetworkContainers

func (f *Fake) NetworkContainers(_ context.Context, network string) ([]string, error)

func (*Fake) PauseContainer

func (f *Fake) PauseContainer(_ context.Context, id string) error

func (*Fake) PullImage

func (f *Fake) PullImage(_ context.Context, ref string) error

func (*Fake) RemoveContainer

func (f *Fake) RemoveContainer(_ context.Context, id string) error

func (*Fake) RemoveNetwork

func (f *Fake) RemoveNetwork(_ context.Context, id string) error

func (*Fake) RemoveVolume

func (f *Fake) RemoveVolume(_ context.Context, name string) error

func (*Fake) RunContainer

func (f *Fake) RunContainer(_ context.Context, spec engine.ContainerSpec) (int, error)

func (*Fake) Runs

func (f *Fake) Runs() []engine.ContainerSpec

Runs are the specs of all one-off containers run so far.

func (*Fake) Save

func (f *Fake) Save(path string) error

Save persists the fake's state.

func (*Fake) SetContainerState

func (f *Fake) SetContainerState(id, state string)

SetContainerState changes a container's state, e.g. to "exited".

func (*Fake) SetInfo

func (f *Fake) SetInfo(i engine.Info)

SetInfo replaces what Info returns.

func (*Fake) SetMounts

func (f *Fake) SetMounts(id string, mounts []engine.Mount)

SetMounts sets the mounts InspectContainer reports for a container.

func (*Fake) SetRuntime added in v0.2.0

func (f *Fake) SetRuntime(id string, r engine.Runtime)

SetRuntime sets how a container last ran, as InspectContainer reports it.

func (*Fake) SetStats added in v0.2.0

func (f *Fake) SetStats(id string, st engine.Stats)

SetStats sets what ContainerStats reports for a container.

func (*Fake) Spec

func (f *Fake) Spec(id string) engine.ContainerSpec

Spec returns the spec a container was created with.

func (*Fake) StartContainer

func (f *Fake) StartContainer(_ context.Context, id string) error

func (*Fake) Subscribers

func (f *Fake) Subscribers() int

Subscribers returns how many Events streams are open; tests wait for a command to listen.

func (*Fake) UnpauseContainer

func (f *Fake) UnpauseContainer(_ context.Context, id string) error

type Seeder

type Seeder interface {
	// SeedContainer creates a stopped container with the given labels and returns its id.
	SeedContainer(t *testing.T, labels map[string]string) string
	// SeedPublished creates a running container that publishes container port 80 on 127.0.0.1
	// (random host port) and exposes port 81 without publishing it.
	SeedPublished(t *testing.T, labels map[string]string) string
	// SeedNetwork creates a network with the given labels and returns its id.
	SeedNetwork(t *testing.T, labels map[string]string) string
	// CheckFile fails the test unless the file in the running container has that content.
	CheckFile(t *testing.T, id, path, content string)
}

Seeder creates resources the Engine interface itself cannot create.

type State

type State struct {
	Info       engine.Info
	Volumes    map[string]engine.Volume
	Containers map[string]engine.Container
	Networks   map[string]engine.Network
	Images     map[string]bool
	Specs      map[string]engine.ContainerSpec // containers created with CreateContainer
	// Aliases are the DNS aliases per container id and network name.
	Aliases map[string]map[string][]string
}

State is the fake daemon's content. It is exported so it can be persisted between processes.

Jump to

Keyboard shortcuts

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