fake

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 10 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CopyCall

type CopyCall struct {
	Host      string
	Container string
	DestDir   string
	Name      string
	Content   []byte
}

CopyCall records one CopyToContainer invocation for assertions.

type ExecCall

type ExecCall struct {
	Host      string
	Container string
	Cmd       []string
}

ExecCall records one ContainerExec invocation for assertions.

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 New

func New() *Fake

New returns a fresh fake.

func (*Fake) AddPod

func (f *Fake) AddPod(host string, p podman.Pod)

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

func (f *Fake) AddVolume(host string, v podman.Volume)

AddVolume seeds a volume on a host so VolumeInspect resolves it. Test-only.

func (*Fake) BuildCachePrune

func (f *Fake) BuildCachePrune(_ context.Context, host string) (podman.PruneReport, error)

func (*Fake) ContainerExec

func (f *Fake) ContainerExec(_ context.Context, host, container string, cmd []string) (podman.ExecResult, error)

func (*Fake) ContainerLogs

func (f *Fake) ContainerLogs(_ context.Context, _, _ string, _ podman.LogOptions) (<-chan podman.LogLine, error)

func (*Fake) ContainerPrune

func (f *Fake) ContainerPrune(_ context.Context, host string) (podman.PruneReport, error)

func (*Fake) CopyToContainer

func (f *Fake) CopyToContainer(_ context.Context, host, container, destDir, name string, content []byte) error

func (*Fake) HostInfo

func (f *Fake) HostInfo(_ context.Context, _ string) (podman.HostInfo, error)

func (*Fake) ImagePrune

func (f *Fake) ImagePrune(_ context.Context, host string, all bool) (podman.PruneReport, error)

func (*Fake) ImagePull

func (f *Fake) ImagePull(_ context.Context, host, ref string) error

func (*Fake) Knows

func (f *Fake) Knows(id string) bool

Knows reports a host as registered unless it's listed in Unknown.

func (*Fake) NetworkEnsure

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

func (*Fake) Ping

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

func (*Fake) PlayKube

func (f *Fake) PlayKube(_ context.Context, hostID, raw string, replace bool, networks ...string) error

func (*Fake) PodInspect

func (f *Fake) PodInspect(_ context.Context, h, name string) (podman.Pod, error)

func (*Fake) PodList

func (f *Fake) PodList(_ context.Context, h string, filters map[string]string) ([]podman.Pod, error)

func (*Fake) PodRemove

func (f *Fake) PodRemove(_ context.Context, h, name string, _ bool) error

func (*Fake) PodRestart

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

func (*Fake) PodStart

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

func (*Fake) PodStop

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

func (*Fake) SecretCreate

func (f *Fake) SecretCreate(_ context.Context, h, name string, value []byte) error

func (*Fake) SecretInspect

func (f *Fake) SecretInspect(_ context.Context, h, name string) (podman.Secret, error)

func (*Fake) SecretList

func (f *Fake) SecretList(_ context.Context, h string) ([]podman.Secret, error)

func (*Fake) SecretRemove

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

func (*Fake) SetHosts

func (f *Fake) SetHosts(_ []config.Host)

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

func (f *Fake) SetVolumeData(host, name string, data []byte)

SetVolumeData seeds a volume and its contents on a host. Test-only.

func (*Fake) UsedHostPorts

func (f *Fake) UsedHostPorts(_ context.Context, h string) ([]podman.PortMapping, error)

func (*Fake) Version

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

func (*Fake) VolumeCreate

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

func (*Fake) VolumeData

func (f *Fake) VolumeData(host, name string) []byte

VolumeData returns the stored contents of a volume (nil if none). Test-only.

func (*Fake) VolumeExport

func (f *Fake) VolumeExport(_ context.Context, h, name string) (io.ReadCloser, error)

func (*Fake) VolumeImport

func (f *Fake) VolumeImport(_ context.Context, h, name string, r io.Reader) error

func (*Fake) VolumeInspect

func (f *Fake) VolumeInspect(_ context.Context, h, name string) (podman.Volume, error)

func (*Fake) VolumePrune

func (f *Fake) VolumePrune(_ context.Context, host string, filters map[string][]string) (podman.PruneReport, error)

func (*Fake) VolumeRemove

func (f *Fake) VolumeRemove(_ context.Context, h, name string, _ bool) error

type PlayCall

type PlayCall struct {
	Host     string
	Replace  bool
	Networks []string
	YAML     string
}

PlayCall records one PlayKube invocation for assertions.

type PruneCall

type PruneCall struct {
	Host    string
	Scope   string              // "images" | "containers" | "buildcache" | "volumes"
	All     bool                // ImagePrune only
	Filters map[string][]string // VolumePrune only
}

PruneCall records one prune invocation for assertions.

Jump to

Keyboard shortcuts

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