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 ¶
- type Container
- type Fake
- func (f *Fake) CopyFrom(context.Context, string, string) (io.ReadCloser, error)
- func (f *Fake) CopyTo(_ context.Context, _, _ string, tarStream io.Reader) error
- func (f *Fake) CreateContainer(_ context.Context, spec runtime.ContainerSpec) (string, error)
- func (f *Fake) EnsureImage(_ context.Context, ref string, _ *runtime.RegistryAuth, progress func(string)) error
- func (f *Fake) EnsureNetwork(_ context.Context, spec runtime.NetworkSpec) (runtime.NetworkInfo, error)
- func (f *Fake) EnsureVolume(_ context.Context, name string, _ map[string]string) error
- func (f *Fake) Exec(_ context.Context, id string, spec runtime.ExecSpec, stdin io.Reader, ...) (int, error)
- func (f *Fake) Get(id string) (Container, bool)
- func (f *Fake) ImageLoad(_ context.Context, tar io.Reader) error
- func (f *Fake) InspectContainer(_ context.Context, id string) (runtime.ContainerState, error)
- func (f *Fake) ListContainers(_ context.Context, labels map[string]string) ([]runtime.ContainerInfo, error)
- func (f *Fake) Logs(ctx context.Context, id string, opts runtime.LogsOptions) (<-chan runtime.LogEntry, error)
- func (f *Fake) Ping(context.Context) error
- func (f *Fake) RemoveContainer(_ context.Context, id string, force bool) error
- func (f *Fake) RemoveNetwork(_ context.Context, name string) error
- func (f *Fake) RemoveVolume(_ context.Context, name string) error
- func (f *Fake) SetRestarting(id string, restarting bool, exitCode int)
- func (f *Fake) Snapshot() []Container
- func (f *Fake) StartContainer(_ context.Context, id string) error
- func (f *Fake) Stats(_ context.Context, id string) (runtime.StatsSample, error)
- func (f *Fake) StopContainer(_ context.Context, id string, _ time.Duration) error
- func (f *Fake) Top(_ context.Context, id string) ([]string, [][]string, error)
- func (f *Fake) VolumeHostPath(_ context.Context, name string) (string, error)
- type Hooks
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 (*Fake) CreateContainer ¶
func (*Fake) EnsureImage ¶
func (*Fake) EnsureNetwork ¶
func (f *Fake) EnsureNetwork(_ context.Context, spec runtime.NetworkSpec) (runtime.NetworkInfo, error)
func (*Fake) EnsureVolume ¶
func (*Fake) InspectContainer ¶
func (*Fake) ListContainers ¶
func (*Fake) RemoveContainer ¶
func (*Fake) SetRestarting ¶
SetRestarting flips a container into (or out of) Docker's crash-loop backoff state for tests.
func (*Fake) StopContainer ¶
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.
Click to show internal directories.
Click to hide internal directories.