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 ¶
- func RunContract(t *testing.T, e engine.Engine, s Seeder)
- type Fake
- func (f *Fake) AddContainer(c engine.Container) string
- func (f *Fake) AddImage(ref string)
- func (f *Fake) AddNetwork(n engine.Network) string
- func (f *Fake) ConnectNetwork(_ context.Context, network, container string, aliases []string) error
- func (f *Fake) ContainerStats(_ context.Context, id string) (engine.Stats, error)
- func (f *Fake) CopyToContainer(_ context.Context, id string, files map[string][]byte) error
- func (f *Fake) CreateContainer(_ context.Context, spec engine.ContainerSpec) (string, error)
- func (f *Fake) CreateNetwork(_ context.Context, name string, labels map[string]string) (engine.Network, error)
- func (f *Fake) CreateVolume(_ context.Context, name string, labels map[string]string) (engine.Volume, error)
- func (f *Fake) DisconnectNetwork(_ context.Context, network, container string) error
- func (f *Fake) Emit(id, action string, attrs map[string]string)
- func (f *Fake) Events(ctx context.Context, labelFilters ...string) (<-chan engine.Event, <-chan error)
- func (f *Fake) Files(id string) map[string][]byte
- func (f *Fake) ImageExists(_ context.Context, ref string) (bool, error)
- func (f *Fake) Info(context.Context) (engine.Info, error)
- func (f *Fake) InspectContainer(_ context.Context, id string) (engine.ContainerDetails, bool, error)
- func (f *Fake) InspectVolume(_ context.Context, name string) (engine.Volume, bool, error)
- func (f *Fake) ListContainers(_ context.Context, labelFilters ...string) ([]engine.Container, error)
- func (f *Fake) ListNetworks(_ context.Context, labelFilters ...string) ([]engine.Network, error)
- func (f *Fake) ListVolumes(_ context.Context, labelFilters ...string) ([]engine.Volume, error)
- func (f *Fake) NetworkContainers(_ context.Context, network string) ([]string, error)
- func (f *Fake) PauseContainer(_ context.Context, id string) error
- func (f *Fake) PullImage(_ context.Context, ref string) error
- func (f *Fake) RemoveContainer(_ context.Context, id string) error
- func (f *Fake) RemoveNetwork(_ context.Context, id string) error
- func (f *Fake) RemoveVolume(_ context.Context, name string) error
- func (f *Fake) RunContainer(_ context.Context, spec engine.ContainerSpec) (int, error)
- func (f *Fake) Runs() []engine.ContainerSpec
- func (f *Fake) Save(path string) error
- func (f *Fake) SetContainerState(id, state string)
- func (f *Fake) SetInfo(i engine.Info)
- func (f *Fake) SetMounts(id string, mounts []engine.Mount)
- func (f *Fake) SetRuntime(id string, r engine.Runtime)
- func (f *Fake) SetStats(id string, st engine.Stats)
- func (f *Fake) Spec(id string) engine.ContainerSpec
- func (f *Fake) StartContainer(_ context.Context, id string) error
- func (f *Fake) Subscribers() int
- func (f *Fake) UnpauseContainer(_ context.Context, id string) error
- type Seeder
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 (*Fake) AddContainer ¶
AddContainer adds a container, as Compose would, and returns its id.
func (*Fake) AddNetwork ¶
AddNetwork adds a network and returns its id.
func (*Fake) ConnectNetwork ¶
func (*Fake) ContainerStats ¶ added in v0.2.0
ContainerStats reports what SetStats set, else a container that uses nothing.
func (*Fake) CopyToContainer ¶
func (*Fake) CreateContainer ¶
func (*Fake) CreateNetwork ¶
func (*Fake) CreateVolume ¶
func (*Fake) DisconnectNetwork ¶
func (*Fake) Emit ¶
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) InspectContainer ¶
func (*Fake) InspectVolume ¶
func (*Fake) ListContainers ¶
func (*Fake) ListNetworks ¶
func (*Fake) ListVolumes ¶
func (*Fake) NetworkContainers ¶
func (*Fake) RunContainer ¶
func (*Fake) Runs ¶
func (f *Fake) Runs() []engine.ContainerSpec
Runs are the specs of all one-off containers run so far.
func (*Fake) SetContainerState ¶
SetContainerState changes a container's state, e.g. to "exited".
func (*Fake) SetRuntime ¶ added in v0.2.0
SetRuntime sets how a container last ran, as InspectContainer reports it.
func (*Fake) Spec ¶
func (f *Fake) Spec(id string) engine.ContainerSpec
Spec returns the spec a container was created with.
func (*Fake) Subscribers ¶
Subscribers returns how many Events streams are open; tests wait for a command to listen.
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.