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
- Variables
- func App(namespace, name, version string) model.Desired
- func Dump(r model.Report) string
- func Embedded(name, version string) model.Desired
- func False(c model.Condition, reason string) bool
- func Module(name, version string) model.Desired
- func Restored(desired model.Desired, settings addonutils.Values) model.BootPackage
- func Running(r model.Report, version string) bool
- func True(c model.Condition) bool
- func Unknown(c model.Condition) bool
- func WithSettings(desired model.Desired, values addonutils.Values) model.Desired
- type CRDs
- type Clock
- func (c *Clock) Advance(d time.Duration)
- func (c *Clock) AdvanceTo(at time.Time)
- func (c *Clock) ArmedAt(at time.Time) int
- func (c *Clock) NewTimer(d time.Duration) retry.Timer
- func (c *Clock) Next() (time.Time, bool)
- func (c *Clock) NextOf(owner string) (time.Time, bool)
- func (c *Clock) Now() time.Time
- func (c *Clock) Owned(owner string) retry.Clock
- type Disk
- type Faults
- type GlobalModule
- func (g *GlobalModule) EnabledModules() []string
- func (g *GlobalModule) ImagesDigests(name string) map[string]string
- func (g *GlobalModule) SetCapabilities(apiVersions []string)
- func (g *GlobalModule) SetEnabledModules(modules []string)
- func (g *GlobalModule) SetModulesImagesDigests(digests map[string]map[string]string)
- type Hooks
- func (h *Hooks) Running(name string) bool
- func (h *Hooks) RuntimeChange(name, key string, value any) bool
- func (h *Hooks) RuntimeFailure(name, hook, message string)
- func (h *Hooks) SettingsError(name string, err error)
- func (h *Hooks) Start(ctx, _ context.Context, pkg hooklane.Object, changed func()) (func(), error)
- func (h *Hooks) SyncWrite(name, key string, value any)
- func (h *Hooks) WriteOn(name string, binding shtypes.BindingType, key string, value any)
- type Kit
- func (k *Kit) AdvanceToNextTimer(desc string) time.Duration
- func (k *Kit) AdvanceToTimerOf(owner, desc string) time.Duration
- func (k *Kit) ApplyModule(desired model.Desired, enabled bool)
- func (k *Kit) Boot(packages ...model.BootPackage) error
- func (k *Kit) Count(mark int, entry string) int
- func (k *Kit) History(name string) []model.Report
- func (k *Kit) Index(mark int, entry string) int
- func (k *Kit) Log(mark int) []string
- func (k *Kit) Mark() int
- func (k *Kit) MustBoot(packages ...model.BootPackage)
- func (k *Kit) Report(name string) model.Report
- func (k *Kit) Shutdown()
- func (k *Kit) Wait(desc string, cond func() bool)
- func (k *Kit) WaitArmed(desc string)
- func (k *Kit) WaitFor(d time.Duration, cond func() bool) bool
- func (k *Kit) WaitLog(mark int, entry string)
- func (k *Kit) WaitReport(name, desc string, pred func(model.Report) bool) model.Report
- type Loader
- type Nelm
- func (n *Nelm) Delete(ctx context.Context, _ string, name string) error
- func (n *Nelm) Drift(name string) bool
- func (n *Nelm) HasMonitor(name string) bool
- func (n *Nelm) Installed(name string) bool
- func (n *Nelm) PauseMonitor(name string)
- func (n *Nelm) RemoveMonitor(name string)
- func (n *Nelm) ResumeMonitor(name string)
- func (n *Nelm) Upgrade(ctx context.Context, _ string, pkg nelm.Package, applying, drifted func()) error
- type Notifier
- type Observed
- type Option
- type Orphans
- type Package
- func (p *Package) AppliedSettingsVersion() int
- func (p *Package) ApplySettings(version int, settings addonutils.Values) error
- func (p *Package) DisableHooks()
- func (p *Package) GetConstraints() schedule.Constraints
- func (p *Package) GetDigests() map[string]string
- func (p *Package) GetEnabledScriptDescriptor() *script.Descriptor
- func (p *Package) GetExclusiveGroup() string
- func (p *Package) GetHooksByBinding(shtypes.BindingType) []hooks.ControllableHook
- func (p *Package) GetHooksQueues() []string
- func (p *Package) GetMaintenance() nelm.MaintenanceState
- func (p *Package) GetName() string
- func (p *Package) GetPath() string
- func (p *Package) GetRuntimeValues() string
- func (p *Package) GetSettings() addonutils.Values
- func (p *Package) GetValues() addonutils.Values
- func (p *Package) GetValuesChecksum() string
- func (p *Package) GetVersion() *semver.Version
- func (p *Package) InitializeHooks()
- func (p *Package) LatestSettingsVersion() int
- func (p *Package) RunHookByName(context.Context, string, []bctx.BindingContext) error
- func (p *Package) RunHooksByBinding(ctx context.Context, binding shtypes.BindingType) error
- func (p *Package) SetMaintenance(state nelm.MaintenanceState)
- func (p *Package) SetValue(key string, value any)
- func (p *Package) UnlockKubernetesMonitors(string, ...string)
- func (p *Package) ValidateSettings(_ context.Context, _ int, settings addonutils.Values) (settingscheck.Result, error)
- type Spec
- type Webhooks
- type Window
Constants ¶
const GlobalTimers = "global"
GlobalTimers owns Global's timers on the kit's Clock (AdvanceToTimerOf).
const GlobalVersion = "v1.0.0"
GlobalVersion is the version of the fake global module.
const ModulesNamespace = "d8-system"
ModulesNamespace is the release namespace of modules in the kit.
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 ¶
Epoch is where the kit's clock starts: a Monday, 10:00 UTC.
Functions ¶
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 ¶
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 WithSettings ¶
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 ¶
GetManagedGVKs returns nothing.
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) AdvanceTo ¶
AdvanceTo moves the time to at (never back) and fires every timer due by then.
func (*Clock) Next ¶
Next returns the earliest deadline of the armed timers; false when none is armed.
func (*Clock) Owned ¶
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.
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 ¶
Block holds every call of key until the returned release is called (or the call is cancelled).
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) RuntimeChange ¶
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 ¶
RuntimeFailure records a failed runtime hook in the observations, as a hook lane does.
func (*Hooks) SettingsError ¶
SettingsError makes ValidateSettings of name fail with err (nil clears it).
func (*Hooks) Start ¶
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.
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 (*Kit) AdvanceToNextTimer ¶
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 ¶
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 ¶
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) History ¶
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 ¶
Index returns the position (relative to mark) of the first entry equal to entry; -1 if none.
func (*Kit) MustBoot ¶
func (k *Kit) MustBoot(packages ...model.BootPackage)
MustBoot is Boot that fails the test on an error.
func (*Kit) Wait ¶
Wait waits until cond holds, woken by every change the kit sees; it fails the test after Timeout with desc.
func (*Kit) WaitArmed ¶
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 ¶
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.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader serves Specs by name and version; an unknown version loads the zero Spec.
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) Drift ¶
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 ¶
HasMonitor reports whether name has a drift monitor.
func (*Nelm) PauseMonitor ¶
PauseMonitor pauses name's monitor.
func (*Nelm) RemoveMonitor ¶
RemoveMonitor records "remove-monitor:<name>".
func (*Nelm) ResumeMonitor ¶
ResumeMonitor resumes name's monitor.
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier fakes the update notification webhook: records "notify:<name>@<version>" (fault key).
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 ¶
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 ¶
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>".
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 ¶
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 ¶
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 ¶
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 ¶
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) GetRuntimeValues ¶
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 ¶
GetValuesChecksum hashes the values hooks and templates see.
func (*Package) GetVersion ¶
GetVersion is the version the image declares.
func (*Package) InitializeHooks ¶
func (p *Package) InitializeHooks()
InitializeHooks records the initialization.
func (*Package) LatestSettingsVersion ¶
LatestSettingsVersion is the spec's latest settings-schema version.
func (*Package) RunHookByName ¶
RunHookByName does nothing: runtime hooks are simulated with Hooks.RuntimeChange.
func (*Package) RunHooksByBinding ¶
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 ¶
SetValue writes a hook value, as a hook patch would; the caller decides whether to call changed.
func (*Package) UnlockKubernetesMonitors ¶
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 ¶
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) NextAllowedTime ¶
NextAllowedTime is the opening time; a day ahead while it is unset.