fakeruntime

package
v0.1.0-alpha.8 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fakeruntime is an in-memory ContainerRuntime for unit and simcluster tests. Containers "run" instantly; behavior can be scripted per image via Hooks (fail pulls, exit with codes, block starts).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	ID      string
	Spec    runtime.ContainerSpec
	Running bool
	// Restarting mimics Docker's crash-loop backoff: Running stays true and
	// Inspect reports no bound ports, exactly like the real engine (T-98).
	Restarting bool
	Created    time.Time
	Started    time.Time
	Stopped    time.Time
	Exit       int
	IP         string
	// LogLines can be appended by tests; Logs() serves them.
	LogLines []runtime.LogEntry
}

Container is the fake's record of one container.

type Fake

type Fake struct {
	Hooks Hooks
	// contains filtered or unexported fields
}

Fake implements runtime.ContainerRuntime.

func New

func New() *Fake

func (*Fake) CopyFrom

func (f *Fake) CopyFrom(context.Context, string, string) (io.ReadCloser, error)

func (*Fake) CopyTo

func (f *Fake) CopyTo(_ context.Context, _, _ string, tarStream io.Reader) error

func (*Fake) CreateContainer

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

func (*Fake) EnsureImage

func (f *Fake) EnsureImage(_ context.Context, ref string, _ *runtime.RegistryAuth, progress func(string)) error

func (*Fake) EnsureNetwork

func (f *Fake) EnsureNetwork(_ context.Context, spec runtime.NetworkSpec) (runtime.NetworkInfo, error)

func (*Fake) EnsureVolume

func (f *Fake) EnsureVolume(_ context.Context, name string, _ map[string]string) error

func (*Fake) Exec

func (f *Fake) Exec(_ context.Context, id string, spec runtime.ExecSpec, stdin io.Reader, stdout, stderr io.Writer, resize <-chan runtime.TermSize) (int, error)

func (*Fake) Get

func (f *Fake) Get(id string) (Container, bool)

Get returns one container by id.

func (*Fake) ImageLoad

func (f *Fake) ImageLoad(_ context.Context, tar io.Reader) error

func (*Fake) InspectContainer

func (f *Fake) InspectContainer(_ context.Context, id string) (runtime.ContainerState, error)

func (*Fake) ListContainers

func (f *Fake) ListContainers(_ context.Context, labels map[string]string) ([]runtime.ContainerInfo, error)

func (*Fake) Logs

func (f *Fake) Logs(ctx context.Context, id string, opts runtime.LogsOptions) (<-chan runtime.LogEntry, error)

func (*Fake) Ping

func (f *Fake) Ping(context.Context) error

func (*Fake) RemoveContainer

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

func (*Fake) RemoveNetwork

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

func (*Fake) RemoveVolume

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

func (*Fake) SetRestarting

func (f *Fake) SetRestarting(id string, restarting bool, exitCode int)

SetRestarting flips a container into (or out of) Docker's crash-loop backoff state for tests.

func (*Fake) Snapshot

func (f *Fake) Snapshot() []Container

Snapshot returns a copy of all containers for assertions.

func (*Fake) StartContainer

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

func (*Fake) Stats

func (f *Fake) Stats(_ context.Context, id string) (runtime.StatsSample, error)

func (*Fake) StopContainer

func (f *Fake) StopContainer(_ context.Context, id string, _ time.Duration) error

func (*Fake) Top

func (f *Fake) Top(_ context.Context, id string) ([]string, [][]string, error)

func (*Fake) VolumeHostPath

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

type Hooks

type Hooks struct {
	// FailPull returns an error for EnsureImage of matching refs.
	FailPull func(ref string) error
	// OnStart may return an error to fail StartContainer.
	OnStart func(c *Container) error
	// ExitImmediately: containers of this image exit right after start with
	// the given code.
	ExitCode func(image string) (code int, exits bool)
	// Exec, when set, overrides Exec for a running container — e.g. to echo
	// stdin→stdout or return a specific exit code (T-49).
	Exec func(id string, spec runtime.ExecSpec, stdin io.Reader, stdout, stderr io.Writer, resize <-chan runtime.TermSize) (int, error)
}

Hooks lets tests inject failures and behaviors keyed by image ref.

Jump to

Keyboard shortcuts

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