dockerfake

package
v1.0.0-rc.12 Latest Latest
Warning

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

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

Documentation

Overview

Package dockerfake models the small Docker daemon contract used by tests. It is a recording daemon, not a deployment driver or AppTown fixture.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerID

func ContainerID(name string) string

ContainerID is the ID the fake printed for the container it made under name.

func ImageID

func ImageID(ref string) string

ImageID is the immutable image the fixture resolves a reference to.

func StorageContainer

func StorageContainer(args []string) map[string]any

StorageContainer is the image/mount observation of a recorded docker run.

Types

type Daemon

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

func New

func New() *Daemon

func (*Daemon) Close

func (d *Daemon) Close()

Close stops every published port's relay.

func (*Daemon) Commands

func (d *Daemon) Commands() [][]string

func (*Daemon) Configs

func (d *Daemon) Configs() []string

Configs are the client configuration each command named, in order ("" is the ambient one).

func (*Daemon) IsDiskRead

func (d *Daemon) IsDiskRead(args []string) bool

IsDiskRead identifies this daemon's disk commands, including completed reads.

func (*Daemon) Limits

func (d *Daemon) Limits(name string) (memory, nanoCPUs int64)

Limits is the memory and NanoCPUs the daemon holds a container to, as its runs and updates set them (0: no limit).

func (*Daemon) Matching

func (d *Daemon) Matching(prefix string) [][]string

func (*Daemon) PublishPorts

func (d *Daemon) PublishPorts()

PublishPorts makes the daemon publish a container's port as Docker does: a container run with `-p addr:N:inner` answers at N from every start, and one run with `-p addr::inner` answers at a port Docker picks at each start (run, start, restart), so the port it had before goes dead. Each published port relays to the port SetPort names. Without it every running container answers at that port. Close stops the relays.

func (*Daemon) ResetCommands

func (d *Daemon) ResetCommands()

func (*Daemon) Run

func (d *Daemon) Run(_ context.Context, _ string, req docker.Command) ([]byte, error)

func (*Daemon) Running

func (d *Daemon) Running(name string) bool

Running says whether the daemon holds the container running now.

func (*Daemon) SetCommandReply

func (d *Daemon) SetCommandReply(reply func(docker.Command) ([]byte, error, bool))

SetCommandReply scripts stream-bearing commands such as backup copies. The callback must not call methods on this daemon while Run holds its lock.

func (*Daemon) SetDisk

func (d *Daemon) SetDisk(totalBytes, freeBytes int64)

SetDisk scripts what df says of the data folder's filesystem (100 GiB with 90 GiB free unless set).

func (*Daemon) SetExitCode

func (d *Daemon) SetExitCode(name string, code int)

SetExitCode scripts the container's last exit code.

func (*Daemon) SetHostInfo

func (d *Daemon) SetHostInfo(memoryBytes int64, cpus int, dataRoot string)

SetHostInfo scripts what docker info says the daemon can give containers (8 GiB and 8 CPUs unless set).

func (*Daemon) SetOOMKilled

func (d *Daemon) SetOOMKilled(name string, killed bool)

SetOOMKilled scripts whether the container's last exit was an out-of-memory kill, what its inspected state says.

func (*Daemon) SetPort

func (d *Daemon) SetPort(port int)

func (*Daemon) SetReply

func (d *Daemon) SetReply(reply func([]string) ([]byte, error, bool))

func (*Daemon) SetRestartCount

func (d *Daemon) SetRestartCount(name string, count int)

SetRestartCount scripts Docker's restart-policy counter for a container, what `inspect -f {{.RestartCount}}` answers.

func (*Daemon) SetResults

func (d *Daemon) SetResults(answers func(containerresulttest.Command) (containerresulttest.Answer, bool))

SetReply scripts a daemon response after recording the command. Returning false lets the daemon answer from its ordinary container state. SetResults answers result reads (containerresult.Run and Exec) as answers says, before anything else this daemon does; ok false leaves a call to the rest. The containers keep their stdout to themselves, as a daemon that lost it would.

func (*Daemon) SetRunning

func (d *Daemon) SetRunning(name string, running bool)

func (*Daemon) SetStorageContainer

func (d *Daemon) SetStorageContainer(name, image, volume, path string)

SetStorageContainer supplies a fixture's observed engine and named data mount. SetRunning alone does not invent compatibility evidence for retained data.

func (*Daemon) SetVolume

func (d *Daemon) SetVolume(name string, exists bool)

SetVolume supplies an existing or absent named volume in a host fixture.

Jump to

Keyboard shortcuts

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