Documentation
¶
Overview ¶
Package fake is an in-memory implementation of podman.Client used by tests. It models pods, secrets, and volumes as maps keyed by host ID.
Index ¶
- type CopyCall
- type ExecCall
- type Fake
- func (f *Fake) AddPod(host string, p podman.Pod)
- func (f *Fake) AddVolume(host string, v podman.Volume)
- func (f *Fake) BuildCachePrune(_ context.Context, host string) (podman.PruneReport, error)
- func (f *Fake) ContainerExec(_ context.Context, host, container string, cmd []string) (podman.ExecResult, error)
- func (f *Fake) ContainerLogs(_ context.Context, _, _ string, _ podman.LogOptions) (<-chan podman.LogLine, error)
- func (f *Fake) ContainerPrune(_ context.Context, host string) (podman.PruneReport, error)
- func (f *Fake) CopyToContainer(_ context.Context, host, container, destDir, name string, content []byte) error
- func (f *Fake) FailPodListFor(tmplID string, err error)
- func (f *Fake) HostInfo(_ context.Context, _ string) (podman.HostInfo, error)
- func (f *Fake) ImagePrune(_ context.Context, host string, all bool) (podman.PruneReport, error)
- func (f *Fake) ImagePull(_ context.Context, host, ref string) error
- func (f *Fake) Knows(id string) bool
- func (f *Fake) NetworkEnsure(_ context.Context, host, name string) error
- func (f *Fake) Ping(_ context.Context, _ string) error
- func (f *Fake) PlayKube(_ context.Context, hostID, raw string, replace bool, networks ...string) error
- func (f *Fake) PodInspect(_ context.Context, h, name string) (podman.Pod, error)
- func (f *Fake) PodList(_ context.Context, h string, filters map[string]string) ([]podman.Pod, error)
- func (f *Fake) PodListCallCount() int
- func (f *Fake) PodRemove(_ context.Context, h, name string, _ bool) error
- func (f *Fake) PodRestart(_ context.Context, h, name string) error
- func (f *Fake) PodStart(_ context.Context, h, name string) error
- func (f *Fake) PodStop(_ context.Context, h, name string) error
- func (f *Fake) SecretCreate(_ context.Context, h, name string, value []byte) error
- func (f *Fake) SecretInspect(_ context.Context, h, name string) (podman.Secret, error)
- func (f *Fake) SecretList(_ context.Context, h string) ([]podman.Secret, error)
- func (f *Fake) SecretRemove(_ context.Context, h, name string) error
- func (f *Fake) SetHosts(_ []config.Host)
- func (f *Fake) SetVolumeData(host, name string, data []byte)
- func (f *Fake) UsedHostPorts(_ context.Context, h string) ([]podman.PortMapping, error)
- func (f *Fake) Version(_ context.Context, _ string) (string, error)
- func (f *Fake) VolumeCreate(_ context.Context, h, name string) error
- func (f *Fake) VolumeData(host, name string) []byte
- func (f *Fake) VolumeExport(_ context.Context, h, name string) (io.ReadCloser, error)
- func (f *Fake) VolumeImport(_ context.Context, h, name string, r io.Reader) error
- func (f *Fake) VolumeInspect(_ context.Context, h, name string) (podman.Volume, error)
- func (f *Fake) VolumePrune(_ context.Context, host string, filters map[string][]string) (podman.PruneReport, error)
- func (f *Fake) VolumeRemove(_ context.Context, h, name string, _ bool) error
- type PlayCall
- type PruneCall
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// SecretData stores the raw bytes passed to SecretCreate, keyed by
// (hostID, name). Tests can decode them to assert the wrapped K8s Secret
// structure (metadata.name, data keys).
SecretData map[string]map[string][]byte // hostID -> name -> raw value bytes
// Optional hooks for tests that want to inject errors.
PlayKubeErr error
// PlayKubePodStatus overrides the status assigned to pods created by
// PlayKube. Empty means "Running". Lets a test force a played pod to stay
// un-healthy so a verify-poll times out.
PlayKubePodStatus string
// PlayKubeContainerStatus overrides the status of containers created by
// PlayKube. Empty means "Running". Lets a test make a pod report Running
// while a container is not, exercising the migrate container-level verify.
PlayKubeContainerStatus string
// PlayKubeContainerHealth sets the Health status of containers created by
// PlayKube (default "" = no healthcheck declared). Lets a test drive the
// migrate readiness gate.
PlayKubeContainerHealth string
// ExportErr, if non-nil, makes VolumeExport fail immediately.
ExportErr error
// ImportErr, if non-nil, makes VolumeImport fail immediately (without
// reading the supplied reader) — models a destination that rejects the import.
ImportErr error
// ImportTransform, if non-nil, rewrites the bytes VolumeImport stores on the
// destination — lets a test simulate a lossy/corrupting copy so the source
// and dest manifests diverge.
ImportTransform func(host, name string, in []byte) []byte
// ExportReader, if non-nil, overrides VolumeExport's reader. Lets a test
// supply a stream that errors mid-transfer.
ExportReader func(host, name string) io.ReadCloser
// Prune hooks. PruneReports maps a scope ("images","containers","buildcache",
// "volumes") to the report ImagePrune/etc. should return; absent → empty report.
// PruneErr maps a scope to an error to return. PruneCalls records every call.
PruneReports map[string]podman.PruneReport
PruneErr map[string]error
PruneCalls []PruneCall
// Unknown lists hosts that Knows should report as not registered; nil means
// every host is known. Lets a test exercise the scheduler's unknown-host skip.
Unknown map[string]bool
// VersionStr overrides the version Version reports; empty means "fake-1.0".
VersionStr string
// PullErr, if non-nil, makes ImagePull return this error for matching refs.
// Key is image ref; the empty key matches any ref.
PullErr map[string]error
// PullCalls records every (host, image) pair passed to ImagePull.
PullCalls []struct{ Host, Image string }
// PlayCalls records every PlayKube invocation (host, replace, networks).
PlayCalls []PlayCall
// PodListErr, if non-nil, makes PodList return this error.
PodListErr error
// LogLines, if set, are emitted in order by ContainerLogs before the
// channel closes. Lets tests exercise the streaming response paths.
LogLines []podman.LogLine
// ContainerLogsErr, if non-nil, makes ContainerLogs return this error
// instead of a channel.
ContainerLogsErr error
// UsedHostPortsErr, if non-nil, makes UsedHostPorts return this error.
UsedHostPortsErr error
// PodInspectErr, if non-nil, makes PodInspect return this error (use a
// non-ErrNotFound error to exercise the unexpected-backend-error paths).
PodInspectErr error
// VolumeInspectErr, if non-nil, makes VolumeInspect return this error (use a
// non-ErrNotFound error to exercise the transient-failure path).
VolumeInspectErr error
// SecretCreateErr, if non-nil, makes SecretCreate return this error
// instead of recording the secret.
SecretCreateErr error
// LifecycleErr, if non-nil, makes PodStart/PodStop/PodRestart fail while
// leaving the pod in place, to exercise action-failure paths.
LifecycleErr error
// HostInfoVal is returned by HostInfo when HostInfoErr is nil.
HostInfoVal podman.HostInfo
// HostInfoErr, if non-nil, makes HostInfo return this error.
HostInfoErr error
// HostInfoCalls counts HostInfo invocations (lets a test assert probe throttling).
HostInfoCalls int
// NetworkEnsureCalls records, per host, the network names ensured.
NetworkEnsureCalls map[string][]string
// NetworkEnsureErr, if non-nil, makes NetworkEnsure fail.
NetworkEnsureErr error
// ExecFunc, if set, produces the ContainerExec result for tests. Default
// (nil) returns ExitCode 0, empty output.
ExecFunc func(host, container string, cmd []string) (podman.ExecResult, error)
// ExecCalls records every ContainerExec invocation.
ExecCalls []ExecCall
// CopyCalls records every CopyToContainer invocation.
CopyCalls []CopyCall
// CopyErr, if non-nil, makes CopyToContainer fail.
CopyErr error
// contains filtered or unexported fields
}
Fake is a thread-safe in-memory podman.Client.
func (*Fake) AddPod ¶
AddPod seeds a pod on a host (with whatever container ports it carries), so a test can occupy host ports or pre-place an instance. Test-only.
func (*Fake) AddVolume ¶
AddVolume seeds a volume on a host so VolumeInspect resolves it. Test-only.
func (*Fake) BuildCachePrune ¶
func (*Fake) ContainerExec ¶
func (*Fake) ContainerLogs ¶
func (*Fake) ContainerPrune ¶
func (*Fake) CopyToContainer ¶
func (*Fake) FailPodListFor ¶ added in v1.0.17
FailPodListFor makes PodList return err whenever it is called with a "podman-api/template" filter equal to tmplID. Test-only.
func (*Fake) ImagePrune ¶
func (*Fake) NetworkEnsure ¶
func (*Fake) PodInspect ¶
func (*Fake) PodListCallCount ¶ added in v1.0.17
PodListCallCount returns the number of PodList invocations so far.
func (*Fake) SecretCreate ¶
func (*Fake) SecretInspect ¶
func (*Fake) SecretList ¶
func (*Fake) SetHosts ¶
SetHosts is a no-op: the fake has no persistent host map — it services any host ID, so a reload does not change behaviour.
func (*Fake) SetVolumeData ¶
SetVolumeData seeds a volume and its contents on a host. Test-only.
func (*Fake) UsedHostPorts ¶
func (*Fake) VolumeData ¶
VolumeData returns the stored contents of a volume (nil if none). Test-only.