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) AddHostBoundPort(host, protocol string, port int)
- 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) ContainerStats(_ context.Context, h string) ([]podman.ContainerStats, 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) HostBoundPorts(_ context.Context, h, protocol string) ([]int, error)
- func (f *Fake) HostInfo(_ context.Context, _ string) (podman.HostInfo, error)
- func (f *Fake) HostUptime(_ context.Context, _ string) (time.Duration, bool, error)
- func (f *Fake) ImagePrune(_ context.Context, host string, all bool) (podman.PruneReport, error)
- func (f *Fake) ImagePull(ctx 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(hosts []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
- func (f *Fake) VolumeUsage(_ context.Context, h string) (map[string]int64, error)
- func (f *Fake) WaitForPodCompletion(_ context.Context, h, name string, _ time.Duration) (int, 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
// SetHostsCalls records every host list passed to SetHosts, in order.
SetHostsCalls [][]config.Host
// 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, along
// with the deadline (if any) on the context ImagePull was actually called
// with. Deadline/HasDeadline let a test assert how tightly the caller
// bounded the pull (e.g. applyImagePullTimeout in internal/instance)
// independent of any package-level ImagePull timeout override.
PullCalls []struct {
Host, Image string
Deadline time.Time
HasDeadline bool
}
// 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
// HostBoundPortsErr, if non-nil, makes HostBoundPorts return this error.
HostBoundPortsErr 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
// HostUptimeVal is returned by HostUptime when HostUptimeErr is nil.
HostUptimeVal time.Duration
// HostUptimeOK is HostUptime's second return value (false = uptime unknown).
HostUptimeOK bool
// HostUptimeErr, if non-nil, makes HostUptime return this error.
HostUptimeErr error
// HostUptimeCalls counts HostUptime invocations.
HostUptimeCalls int
// ContainerStatsVal is returned by ContainerStats, keyed by host ID.
ContainerStatsVal map[string][]podman.ContainerStats
// ContainerStatsErr, if non-nil, makes ContainerStats return this error.
ContainerStatsErr error
// ContainerStatsCalls counts ContainerStats invocations.
ContainerStatsCalls int
// VolumeUsageVal is returned by VolumeUsage, keyed by host ID then volume name.
VolumeUsageVal map[string]map[string]int64
// VolumeUsageErr, if non-nil, makes VolumeUsage return this error.
VolumeUsageErr error
// VolumeUsageCalls counts VolumeUsage invocations.
VolumeUsageCalls 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) AddHostBoundPort ¶ added in v1.0.36
AddHostBoundPort registers port as bound on host for protocol ("tcp" or "udp"), for HostBoundPorts to report back — e.g. modeling vedanta's native charon holding udp/500 exclusively, outside podman's own visibility.
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) ContainerStats ¶ added in v1.0.28
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) HostBoundPorts ¶ added in v1.0.36
HostBoundPorts returns the ports a test has registered via AddHostBoundPort for (h, protocol) — standing in for a real /proc/net/<protocol> read. Models a plain host-level bind podman itself has no visibility into (a native systemd service, e.g.), distinct from UsedHostPorts' podman-managed container ports above.
func (*Fake) HostUptime ¶ added in v1.0.36
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 does not change behaviour — the fake has no persistent host map and services any host ID — but it RECORDS the call in SetHostsCalls. Behaviour being a no-op is exactly why a caller that forgets to propagate a host-list change to the real client (podman.Real keeps its own map) is invisible to every fake-backed test; the recorder makes that observable.
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.
func (*Fake) VolumeExport ¶
func (*Fake) VolumeImport ¶
func (*Fake) VolumeInspect ¶
func (*Fake) VolumePrune ¶
func (*Fake) VolumeRemove ¶
func (*Fake) VolumeUsage ¶ added in v1.0.28
func (*Fake) WaitForPodCompletion ¶ added in v1.0.35
func (f *Fake) WaitForPodCompletion(_ context.Context, h, name string, _ time.Duration) (int, error)
WaitForPodCompletion computes its result from the containers already recorded on the pod: every container must have Exited=true to succeed, returning the first non-zero ExitCode found (else 0). Any container still not Exited is treated as never finishing within the fake's synchronous model, so it returns podman.ErrWaitTimeout immediately regardless of the requested timeout — tests drive this by seeding pod/container state via AddPod rather than by waiting on a clock.