enginetest

package
v1.78.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package enginetest is the scenario kit of the package engine: a real core, scheduler, package Reconcilers, Currents and Global over fakes of the disk, the loader, nelm, the hook bindings, the orphan purge and Global's CRD and webhook services. Tests only: no production code may import it. Every fake call is recorded in one ordered log, and every wait is bounded and woken by the engine's own signals (the Report notify and the fakes' calls), never by sleeping.

Index

Constants

View Source
const GlobalTimers = "global"

GlobalTimers owns Global's timers on the kit's Clock (AdvanceToTimerOf).

View Source
const GlobalVersion = "v1.0.0"

GlobalVersion is the version of the fake global module.

View Source
const ModulesNamespace = "d8-system"

ModulesNamespace is the release namespace of modules in the kit.

View Source
const Timeout = 20 * time.Second

Timeout bounds every wait of the kit; retries and windows wait on the kit's Clock, not on it.

Variables

View Source
var Epoch = time.Date(2026, time.January, 5, 10, 0, 0, 0, time.UTC)

Epoch is where the kit's clock starts: a Monday, 10:00 UTC.

Functions

func App

func App(namespace, name, version string) model.Desired

App is the desired state of the application namespace/name at version.

func Dump

func Dump(r model.Report) string

Dump renders a Report for failure messages and comparisons.

func Embedded

func Embedded(name, version string) model.Desired

Embedded is the desired state of an embedded module at version.

func False

func False(c model.Condition, reason string) bool

False reports whether c is False with reason ("" matches any reason).

func Module

func Module(name, version string) model.Desired

Module is the desired state of a downloaded module at version with empty settings.

func Restored

func Restored(desired model.Desired, settings addonutils.Values) model.BootPackage

Restored is the boot checkpoint of a package installed at version with settings values (nil: absent checkpoint).

func Running

func Running(r model.Report, version string) bool

Running reports whether r shows version installed and applied: CurrentVersion, the Current section of that version with HooksProcessed, ManifestsApplied and Installed True, and no candidate.

func True

func True(c model.Condition) bool

True reports whether c is True.

func Unknown

func Unknown(c model.Condition) bool

Unknown reports whether c was not reported.

func WithSettings

func WithSettings(desired model.Desired, values addonutils.Values) model.Desired

WithSettings returns desired with settings values.

Types

type CRDs

type CRDs struct {
	// contains filtered or unexported fields
}

CRDs fakes the CRD installer of Global: records "crds:<module>".

func (*CRDs) GetManagedGVKs

func (c *CRDs) GetManagedGVKs([]string) []string

GetManagedGVKs returns nothing.

func (*CRDs) HasCRDs

func (c *CRDs) HasCRDs(string) error

HasCRDs reports that no fake module ships CRDs.

func (*CRDs) Install

func (c *CRDs) Install(ctx context.Context, name, _ string) error

Install records "crds:<name>" (fault key).

type Clock

type Clock struct {
	// contains filtered or unexported fields
}

Clock is the engine's clock in the kit (the package Reconcilers, Currents and Global): time moves only when a test advances it, and every armed timer wakes the kit's waiters.

func (*Clock) Advance

func (c *Clock) Advance(d time.Duration)

Advance moves the time by d and fires every timer due by then.

func (*Clock) AdvanceTo

func (c *Clock) AdvanceTo(at time.Time)

AdvanceTo moves the time to at (never back) and fires every timer due by then.

func (*Clock) ArmedAt

func (c *Clock) ArmedAt(at time.Time) int

ArmedAt returns how many timers are armed for exactly at.

func (*Clock) NewTimer

func (c *Clock) NewTimer(d time.Duration) retry.Timer

NewTimer returns a timer armed at now+d.

func (*Clock) Next

func (c *Clock) Next() (time.Time, bool)

Next returns the earliest deadline of the armed timers; false when none is armed.

func (*Clock) NextOf

func (c *Clock) NextOf(owner string) (time.Time, bool)

NextOf is Next over the timers of owner (Owned).

func (*Clock) Now

func (c *Clock) Now() time.Time

Now returns the kit's time.

func (*Clock) Owned

func (c *Clock) Owned(owner string) retry.Clock

Owned returns the clock as owner sees it: its timers carry owner, so a test can wait for them (NextOf) rather than for whichever timer is armed first. A Reset counts from the time owner last read, as retry.Arm means it: a test advancing between the owner's Now and its Reset would otherwise move the deadline by the whole advance and lose the fire Reset discards.

type Disk

type Disk struct {
	// contains filtered or unexported fields
}

Disk is the fake disk backend: attach and detach by instance (name@version), with faults.

func (*Disk) Attach

func (d *Disk) Attach(ctx context.Context, _ registry.Remote, instance, _, _ string) error

Attach records "attach:<instance>".

func (*Disk) Attached

func (d *Disk) Attached() []string

Attached returns the attached instances, sorted.

func (*Disk) Detach

func (d *Disk) Detach(ctx context.Context, instance string) error

Detach records "detach:<instance>".

type Faults

type Faults struct {
	// contains filtered or unexported fields
}

Faults programs the fakes' failures and blocks, keyed by the call's record key (for example "attach:app@v1.0.0", "upgrade:app", "hook:app:BeforeHelm"; see each fake). Safe for concurrent use.

func (*Faults) Block

func (f *Faults) Block(key string) func()

Block holds every call of key until the returned release is called (or the call is cancelled).

func (*Faults) Clear

func (f *Faults) Clear(key string)

Clear removes every fault of key.

func (*Faults) Fail

func (f *Faults) Fail(key string, err error)

Fail makes every call of key fail with err until Clear.

func (*Faults) FailTimes

func (f *Faults) FailTimes(key string, n int, err error)

FailTimes makes the next n calls of key fail with err.

type GlobalModule

type GlobalModule struct {
	*Package
	// contains filtered or unexported fields
}

GlobalModule is the fake global module (global.Module).

func (*GlobalModule) EnabledModules

func (g *GlobalModule) EnabledModules() []string

EnabledModules returns the last published enabled set.

func (*GlobalModule) ImagesDigests

func (g *GlobalModule) ImagesDigests(name string) map[string]string

ImagesDigests returns the last published image digests of module name; nil without any.

func (*GlobalModule) SetCapabilities

func (g *GlobalModule) SetCapabilities(apiVersions []string)

SetCapabilities publishes the capabilities into the global values.

func (*GlobalModule) SetEnabledModules

func (g *GlobalModule) SetEnabledModules(modules []string)

SetEnabledModules publishes the enabled set into the global values.

func (*GlobalModule) SetModulesImagesDigests

func (g *GlobalModule) SetModulesImagesDigests(digests map[string]map[string]string)

SetModulesImagesDigests records the published image digests; like the real module, outside the values, so they do not change Global's Output.

type Hooks

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

Hooks fakes hooklane.Router.Start: start (with a fault), its stop, and the runtime hooks' changed callback, plus the per-binding programs of the package objects.

func (*Hooks) Running

func (h *Hooks) Running(name string) bool

Running reports whether name's hooks are enabled.

func (*Hooks) RuntimeChange

func (h *Hooks) RuntimeChange(name, key string, value any) bool

RuntimeChange runs a runtime hook of name that writes key=value and reports the change, as a hook lane does. False when name's hooks are not running.

func (*Hooks) RuntimeFailure

func (h *Hooks) RuntimeFailure(name, hook, message string)

RuntimeFailure records a failed runtime hook in the observations, as a hook lane does.

func (*Hooks) SettingsError

func (h *Hooks) SettingsError(name string, err error)

SettingsError makes ValidateSettings of name fail with err (nil clears it).

func (*Hooks) Start

func (h *Hooks) Start(ctx, _ context.Context, pkg hooklane.Object, changed func()) (func(), error)

Start records "enable-hooks:<name>" (fault key) and keeps changed for RuntimeChange. A failed enable stops what it started, as the real one does; the stop it returns is idempotent. The synchronizations' writes (SyncWrite) land and report the change, as a hook lane does.

func (*Hooks) SyncWrite

func (h *Hooks) SyncWrite(name, key string, value any)

SyncWrite makes the synchronizations of name write key=value whenever its hooks start.

func (*Hooks) WriteOn

func (h *Hooks) WriteOn(name string, binding shtypes.BindingType, key string, value any)

WriteOn makes binding of name write key=value when it runs (AfterHelm changing values).

type Kit

type Kit struct {
	Engine    *core.Engine
	Scheduler *schedule.Scheduler

	// Clock is the engine's clock: retries and windows wait until a test advances it.
	Clock    *Clock
	Faults   *Faults
	Disk     *Disk
	Loader   *Loader
	Nelm     *Nelm
	Hooks    *Hooks
	Observed *Observed
	Orphans  *Orphans
	CRDs     *CRDs
	Webhooks *Webhooks
	Notifier *Notifier
	// Global is the fake global module; nil without WithGlobal.
	Global *GlobalModule
	// GlobalSettings is Global's boot checkpoint, empty values by default; set it before Boot (nil:
	// Global waits for its first Apply and holds the barrier until then).
	GlobalSettings *model.Settings
	// EmbeddedDir is the image directory of embedded modules.
	EmbeddedDir string
	// contains filtered or unexported fields
}

Kit is one engine under test with its fakes.

func New

func New(t testing.TB, opts ...Option) *Kit

New builds an engine with fakes; Shutdown runs at the test's cleanup.

func (*Kit) AdvanceToNextTimer

func (k *Kit) AdvanceToNextTimer(desc string) time.Duration

AdvanceToNextTimer waits until an engine timer is armed (a retry's backoff, a window), then moves the clock to its deadline, which fires it. It returns the time moved.

func (*Kit) AdvanceToTimerOf

func (k *Kit) AdvanceToTimerOf(owner, desc string) time.Duration

AdvanceToTimerOf is AdvanceToNextTimer over the timers of owner (Clock.Owned): another owner's timer armed first, at the same deadline, would otherwise be fired before owner's is armed.

func (*Kit) ApplyModule

func (k *Kit) ApplyModule(desired model.Desired, enabled bool)

ApplyModule applies desired carrying enabled as its intent, as the facade does.

func (*Kit) Boot

func (k *Kit) Boot(packages ...model.BootPackage) error

Boot boots the engine with packages (and Global with WithGlobal). Without Global it resumes the scheduler as the default tree's wiring does after addon-operator's converge.

func (*Kit) Count

func (k *Kit) Count(mark int, entry string) int

Count returns how many log entries since mark equal entry.

func (*Kit) History

func (k *Kit) History(name string) []model.Report

History returns the distinct Reports of name in the order they were notified (collapsed when the collector read several changes at once).

func (*Kit) Index

func (k *Kit) Index(mark int, entry string) int

Index returns the position (relative to mark) of the first entry equal to entry; -1 if none.

func (*Kit) Log

func (k *Kit) Log(mark int) []string

Log returns the log from mark (Mark) on.

func (*Kit) Mark

func (k *Kit) Mark() int

Mark returns the position of the next log entry.

func (*Kit) MustBoot

func (k *Kit) MustBoot(packages ...model.BootPackage)

MustBoot is Boot that fails the test on an error.

func (*Kit) Report

func (k *Kit) Report(name string) model.Report

Report returns name's Report.

func (*Kit) Shutdown

func (k *Kit) Shutdown()

Shutdown stops the engine and the kit; idempotent.

func (*Kit) Wait

func (k *Kit) Wait(desc string, cond func() bool)

Wait waits until cond holds, woken by every change the kit sees; it fails the test after Timeout with desc.

func (*Kit) WaitArmed

func (k *Kit) WaitArmed(desc string)

WaitArmed waits until an engine timer is armed: a failed attempt has been handled and backs off. Clear a fault only after it: a fault cleared while the attempt is still in its call may let that attempt pass.

func (*Kit) WaitFor

func (k *Kit) WaitFor(d time.Duration, cond func() bool) bool

WaitFor waits up to d for cond; false on timeout. Use it to assert that something does not happen within d after the engine had every chance to do it.

func (*Kit) WaitLog

func (k *Kit) WaitLog(mark int, entry string)

WaitLog waits until entry appears in the log after mark.

func (*Kit) WaitReport

func (k *Kit) WaitReport(name, desc string, pred func(model.Report) bool) model.Report

WaitReport waits until name's Report satisfies pred and returns it.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader serves Specs by name and version; an unknown version loads the zero Spec.

func (*Loader) Latest

func (l *Loader) Latest(name string) *Package

Latest returns the object last loaded for name; nil when none was.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context, kind model.Kind, image model.Image) (model.Package, error)

Load is the lifecycle.LoadFunc; it records "load:<name>@<version>".

func (*Loader) Set

func (l *Loader) Set(name, version string, spec Spec)

Set registers the spec of name at version; version "" applies to every version without its own.

type Nelm

type Nelm struct {
	// contains filtered or unexported fields
}

Nelm is the fake release service: upgrades and deletes with faults, drift monitors, and the ApplyingManifests callback when the values changed since the last upgrade of the name.

func (*Nelm) Delete

func (n *Nelm) Delete(ctx context.Context, _ string, name string) error

Delete records "delete:<name>"; a missing release is no error.

func (*Nelm) Drift

func (n *Nelm) Drift(name string) bool

Drift fires name's drift callback, as the monitor does when release resources are gone. False when name has no monitor or it is paused.

func (*Nelm) HasMonitor

func (n *Nelm) HasMonitor(name string) bool

HasMonitor reports whether name has a drift monitor.

func (*Nelm) Installed

func (n *Nelm) Installed(name string) bool

Installed reports whether name has a release.

func (*Nelm) PauseMonitor

func (n *Nelm) PauseMonitor(name string)

PauseMonitor pauses name's monitor.

func (*Nelm) RemoveMonitor

func (n *Nelm) RemoveMonitor(name string)

RemoveMonitor records "remove-monitor:<name>".

func (*Nelm) ResumeMonitor

func (n *Nelm) ResumeMonitor(name string)

ResumeMonitor resumes name's monitor.

func (*Nelm) Upgrade

func (n *Nelm) Upgrade(ctx context.Context, _ string, pkg nelm.Package, applying, drifted func()) error

Upgrade records "upgrade:<name>" (fault key) and "upgraded:<name>@<version>" on success.

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier fakes the update notification webhook: records "notify:<name>@<version>" (fault key).

func (*Notifier) Notify

func (n *Notifier) Notify(ctx context.Context, a model.Announcement) error

Notify records the announcement unless its fault fails it.

func (*Notifier) Sent

func (n *Notifier) Sent() []model.Announcement

Sent returns the announcements sent so far, in order.

type Observed

type Observed struct {
	// contains filtered or unexported fields
}

Observed fakes the hook-failure part of the observation store.

func (*Observed) HookFailure

func (o *Observed) HookFailure(name string) string

HookFailure returns name's recorded hook failure; "" when none.

type Option

type Option func(*options)

Option configures a Kit.

func WithGlobal

func WithGlobal() Option

WithGlobal runs the engine with Global (EnableModuleV2): a global node, the barrier, the boot gate.

func WithScheduler

func WithScheduler(opts ...schedule.Option) Option

WithScheduler passes options to the real scheduler (version getters, bootstrap condition, ...).

type Orphans

type Orphans struct {
	// contains filtered or unexported fields
}

Orphans fakes the orphan purge of a removed application: records "purge:<name>".

func (*Orphans) Purge

func (o *Orphans) Purge(ctx context.Context, pkg model.Package) error

Purge records "purge:<name>" (fault key).

type Package

type Package struct {
	// contains filtered or unexported fields
}

Package is the fake package object (model.Package): settings, values and hooks in memory. Hook behaviour comes from the kit's Hooks programs, keyed by package name, so it survives reloads.

func (*Package) AppliedSettingsVersion

func (p *Package) AppliedSettingsVersion() int

AppliedSettingsVersion is the settings-schema version of the last ApplySettings.

func (*Package) ApplySettings

func (p *Package) ApplySettings(version int, settings addonutils.Values) error

ApplySettings stores a copy of settings.

func (*Package) DisableHooks

func (p *Package) DisableHooks()

DisableHooks clears the hooks; the next enable runs OnStartup again.

func (*Package) GetConstraints

func (p *Package) GetConstraints() schedule.Constraints

GetConstraints returns the spec's constraints.

func (*Package) GetDigests

func (p *Package) GetDigests() map[string]string

GetDigests returns the spec's image digests.

func (*Package) GetEnabledScriptDescriptor

func (p *Package) GetEnabledScriptDescriptor() *script.Descriptor

GetEnabledScriptDescriptor returns the spec's enabled script; nil when it has none.

func (*Package) GetExclusiveGroup

func (p *Package) GetExclusiveGroup() string

GetExclusiveGroup returns the spec's exclusive group.

func (*Package) GetHooksByBinding

func (p *Package) GetHooksByBinding(shtypes.BindingType) []hooks.ControllableHook

GetHooksByBinding returns no hooks: bindings are faked by the kit's Hooks.

func (*Package) GetHooksQueues

func (p *Package) GetHooksQueues() []string

GetHooksQueues returns no queues: the fake hook bindings own no queue.

func (*Package) GetMaintenance

func (p *Package) GetMaintenance() nelm.MaintenanceState

GetMaintenance returns the maintenance mode last set.

func (*Package) GetName

func (p *Package) GetName() string

GetName is the package name.

func (*Package) GetPath

func (p *Package) GetPath() string

GetPath is the image path the object was loaded from.

func (*Package) GetRuntimeValues

func (p *Package) GetRuntimeValues() string

GetRuntimeValues is empty: the fake renders nothing.

func (*Package) GetSettings

func (p *Package) GetSettings() addonutils.Values

GetSettings returns the effective settings: Defaults overlaid with the stored settings.

func (*Package) GetValues

func (p *Package) GetValues() addonutils.Values

GetValues returns the values hooks and templates see: effective settings plus hook values.

func (*Package) GetValuesChecksum

func (p *Package) GetValuesChecksum() string

GetValuesChecksum hashes the values hooks and templates see.

func (*Package) GetVersion

func (p *Package) GetVersion() *semver.Version

GetVersion is the version the image declares.

func (*Package) InitializeHooks

func (p *Package) InitializeHooks()

InitializeHooks records the initialization.

func (*Package) LatestSettingsVersion

func (p *Package) LatestSettingsVersion() int

LatestSettingsVersion is the spec's latest settings-schema version.

func (*Package) RunHookByName

func (p *Package) RunHookByName(context.Context, string, []bctx.BindingContext) error

RunHookByName does nothing: runtime hooks are simulated with Hooks.RuntimeChange.

func (*Package) RunHooksByBinding

func (p *Package) RunHooksByBinding(ctx context.Context, binding shtypes.BindingType) error

RunHooksByBinding runs the kit's program for (name, binding): a failure, a block until released or cancelled, a values write. OnStartup runs once per enable, as the real object.

func (*Package) SetMaintenance

func (p *Package) SetMaintenance(state nelm.MaintenanceState)

SetMaintenance stores the maintenance mode.

func (*Package) SetValue

func (p *Package) SetValue(key string, value any)

SetValue writes a hook value, as a hook patch would; the caller decides whether to call changed.

func (*Package) UnlockKubernetesMonitors

func (p *Package) UnlockKubernetesMonitors(string, ...string)

UnlockKubernetesMonitors does nothing.

func (*Package) ValidateSettings

func (p *Package) ValidateSettings(_ context.Context, _ int, settings addonutils.Values) (settingscheck.Result, error)

ValidateSettings runs Spec.Validate; it changes nothing.

type Spec

type Spec struct {
	// Constraints of the loaded object; a nil Floor gets the kind's (modules Disable, apps Enable).
	Constraints schedule.Constraints
	// Defaults are merged under the user settings (the effective settings).
	Defaults addonutils.Values
	// Validate rejects settings with its error; nil accepts everything.
	Validate func(values addonutils.Values) error
	// LatestSettingsVersion is the object's latest settings-schema version.
	LatestSettingsVersion int
	// EnabledScript, when set, makes the module ship an enabled script with this descriptor.
	EnabledScript *script.Descriptor
	// ExclusiveGroup is the module's exclusive group (modules.Module.GetExclusiveGroup).
	ExclusiveGroup string
	// Digests are the module's image digests (modules.Module.GetDigests).
	Digests map[string]string
}

Spec describes a package version the fake loader serves; the zero value is a valid package.

type Webhooks

type Webhooks struct {
	// contains filtered or unexported fields
}

Webhooks fakes the conversion webhooks of Global: records "webhooks:<module>".

func (*Webhooks) EnsureWebhooks

func (w *Webhooks) EnsureWebhooks(ctx context.Context, view model.ModuleView) error

EnsureWebhooks records "webhooks:<name>" (fault key).

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is an update window that opens at a set time; the zero value is closed forever.

func (*Window) IsAllowed

func (w *Window) IsAllowed(t time.Time) bool

IsAllowed reports whether t is inside the window.

func (*Window) NextAllowedTime

func (w *Window) NextAllowedTime(t time.Time) time.Time

NextAllowedTime is the opening time; a day ahead while it is unset.

func (*Window) OpenAt

func (w *Window) OpenAt(t time.Time)

OpenAt sets the time the window opens; a time in the past opens it now.

Jump to

Keyboard shortcuts

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