fake

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fake provides in-memory implementations of the control-plane seams (controlplane.Clock, Kubernetes, Registry, Database) for tests. They are deterministic and controllable: time is explicit, state is inspectable, and errors can be injected per operation so engine logic can be exercised against absence and failure without a real cluster, registry, or database (ADR-0010).

The fakes are concurrency-safe so later fault-injection tests can drive them from multiple goroutines under the race detector. This package is licensed Apache-2.0 (see LICENSING.md and ADR-0033); it lives under controlplane/internal so it is importable only by the control plane it supports.

Index

Constants

View Source
const DefaultDigest = "sha256:1111111111111111111111111111111111111111111111111111111111111111"

DefaultDigest is the digest NewBuilder returns until SetDigest overrides it, so a test can assert the built reference the engine deployed without first seeding a value.

Variables

This section is empty.

Functions

func URLFor

func URLFor(app string) string

URLFor is the deterministic connection string the fake returns for app — exposed so a test can assert the engine wrote exactly this value into the secret without the value leaking elsewhere.

Types

type Builder added in v0.13.0

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

Builder is an in-memory controlplane.Builder. Tests seed the digest it returns with SetDigest, inject a build failure with SetError, and read back the source ref and target image it was called with (LastSource / LastTarget) plus the call count, so the in-cluster build orchestration can be exercised — build success feeding the guarded deploy path, and build failure NOT touching it — without standing up a real Kubernetes build Job (ADR-0053 §6).

func NewBuilder added in v0.13.0

func NewBuilder() *Builder

NewBuilder returns a fake builder that returns DefaultDigest on a successful build.

func (*Builder) Build added in v0.13.0

func (b *Builder) Build(_ context.Context, source controlplane.SourceRef, targetImage string, insecure bool, cred controlplane.SourceCredential) (string, error)

func (*Builder) Calls added in v0.13.0

func (b *Builder) Calls() int

Calls returns how many times Build has been called.

func (*Builder) LastCredential added in v0.13.0

func (b *Builder) LastCredential() controlplane.SourceCredential

LastCredential returns the source-provider credential Build was last called with, so a test can assert the engine resolved a configured private-source token and handed it to the builder — or handed the zero credential for a public source (ADR-0057).

func (*Builder) LastInsecure added in v0.13.0

func (b *Builder) LastInsecure() bool

LastInsecure returns the insecure flag Build was last called with — true when the engine pushed to the plain-HTTP in-cluster registry (ADR-0054 §5).

func (*Builder) LastSource added in v0.13.0

func (b *Builder) LastSource() controlplane.SourceRef

LastSource returns the source ref Build was last called with.

func (*Builder) LastTarget added in v0.13.0

func (b *Builder) LastTarget() string

LastTarget returns the target image reference Build was last called with.

func (*Builder) SetDigest added in v0.13.0

func (b *Builder) SetDigest(digest string)

SetDigest seeds the digest a successful Build returns.

func (*Builder) SetError added in v0.13.0

func (b *Builder) SetError(err error)

SetError makes Build return err (nil clears it), exercising the build-failure path where the deploy path must not be touched.

type CapacityProber added in v0.13.0

type CapacityProber struct {
	State controlplane.ClusterResourceState
	Err   error
}

CapacityProber is an in-memory controlplane.CapacityProber: it returns a canned resource state (node allocatable + pod requests) so engine tests can drive ClusterCapacity — the headroom, top consumers, and verdict math — without a cluster (issue #275). An error can be injected to exercise the failure path.

func NewCapacityProber added in v0.13.0

func NewCapacityProber(state controlplane.ClusterResourceState) *CapacityProber

NewCapacityProber returns a prober reporting state.

func (*CapacityProber) ReadResourceState added in v0.13.0

ReadResourceState returns the seeded state (or the injected error).

type Clock

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

Clock is a controllable controlplane.Clock. It does not advance on its own; tests move it with Advance or Set, so every time-dependent result is deterministic.

func NewClock

func NewClock(start time.Time) *Clock

NewClock returns a Clock fixed at start.

func (*Clock) Advance

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

Advance moves the clock forward by d.

func (*Clock) Now

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

Now returns the current fake time.

func (*Clock) Set

func (c *Clock) Set(t time.Time)

Set moves the clock to t.

type ClusterProber

type ClusterProber struct {
	Caps controlplane.ClusterCapabilities
	Err  error
}

ClusterProber is an in-memory controlplane.ClusterProber: it returns a canned capability report (ADR-0034) so engine tests can drive ClusterCapabilities without a cluster. The cluster-derived fields are seeded; the engine fills the DNS field from the providers registry. An error can be injected to exercise the failure path.

func NewClusterProber

func NewClusterProber(caps controlplane.ClusterCapabilities) *ClusterProber

NewClusterProber returns a prober reporting caps.

func (*ClusterProber) DetectCapabilities

func (p *ClusterProber) DetectCapabilities(_ context.Context) (controlplane.ClusterCapabilities, error)

DetectCapabilities returns the seeded report (or the injected error).

type Credentials

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

Credentials is an in-memory controlplane.Credentials. Tests seed tokens with Set, read what SetToken wrote with Get, and inject failure with SetError (OpToken, OpSetToken).

func NewCredentials

func NewCredentials() *Credentials

NewCredentials returns an empty fake credential store.

func (*Credentials) Get

func (c *Credentials) Get(key string) (string, bool)

Get returns the token stored under key and whether it is present, so a test can assert what SetToken wrote into the credential store.

func (*Credentials) Set

func (c *Credentials) Set(key, token string)

Set records that key holds token, seeding the store directly (e.g. a token a prior set wrote).

func (*Credentials) SetError

func (c *Credentials) SetError(op Op, err error)

SetError makes the Token op return err until cleared with SetError(OpToken, nil).

func (*Credentials) SetToken

func (c *Credentials) SetToken(ctx context.Context, key, value string) error

SetToken upserts key=value into the in-memory store, modelling burrowd writing the token it received over the control-plane API into burrow-credentials (ADR-0030). An OpSetToken error can be injected to exercise the failure path.

func (*Credentials) Token

func (c *Credentials) Token(ctx context.Context, key string) (string, error)

type DNSFactory

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

DNSFactory is an in-memory controlplane.DNSFactory. Every DNS(...) returns the same shared provider (so a test can configure and inspect it), unless SetFactoryError makes DNS(...) itself fail. It records the (type, token) pairs it was asked for, so a test can assert the engine read and passed the right token.

func NewDNSFactory

func NewDNSFactory() *DNSFactory

NewDNSFactory returns a factory whose shared provider accepts any token.

func (*DNSFactory) DNS

func (*DNSFactory) LastToken

func (f *DNSFactory) LastToken() (string, int)

LastToken returns the token most recently passed to DNS, and how many times DNS was called.

func (*DNSFactory) Provider

func (f *DNSFactory) Provider() *DNSProvider

Provider returns the shared provider the factory hands out, for configuration and inspection.

func (*DNSFactory) SetDeleteError

func (f *DNSFactory) SetDeleteError(err error)

SetDeleteError makes the shared provider fail DeleteRecord with err.

func (*DNSFactory) SetEnsureError

func (f *DNSFactory) SetEnsureError(err error)

SetEnsureError makes the shared provider fail EnsureRecord with err.

func (*DNSFactory) SetFactoryError

func (f *DNSFactory) SetFactoryError(err error)

SetFactoryError makes DNS(...) return err without handing out a provider.

func (*DNSFactory) SetVerifyError

func (f *DNSFactory) SetVerifyError(err error)

SetVerifyError makes the shared provider reject VerifyAccess with err.

type DNSProvider

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

DNSProvider is an in-memory controlplane.DNSProvider. VerifyAccess and the record operations return their configured error (nil = success); successful EnsureRecord/ DeleteRecord update an inspectable in-memory record set.

func (*DNSProvider) Calls

func (p *DNSProvider) Calls() (ensure, delete int)

Calls returns how many times EnsureRecord and DeleteRecord were invoked.

func (*DNSProvider) DeleteRecord

func (p *DNSProvider) DeleteRecord(ctx context.Context, host string) error

func (*DNSProvider) EnsureRecord

func (p *DNSProvider) EnsureRecord(ctx context.Context, r controlplane.DNSRecord) error

func (*DNSProvider) Record

func (p *DNSProvider) Record(name string) (controlplane.DNSRecord, bool)

Record returns the record currently held for name, and whether one exists.

func (*DNSProvider) VerifyAccess

func (p *DNSProvider) VerifyAccess(ctx context.Context) error

type Database

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

Database is an in-memory controlplane.Database. It stores releases by ID and tracks per-app save order so LatestRelease and Releases are deterministic. Records are deep copied in and out, so callers never share Env/Command memory with the store — the same isolation a real database gives. Errors can be injected per operation.

func NewDatabase

func NewDatabase() *Database

NewDatabase returns an empty fake database with the default guardrail policy.

func (*Database) Addon

func (d *Database) Addon(ctx context.Context, name string) (controlplane.AddonInfo, error)

func (*Database) Addons

func (d *Database) Addons(ctx context.Context) ([]controlplane.AddonInfo, error)

func (*Database) AppEnv

func (d *Database) AppEnv(ctx context.Context, app string) (map[string]string, error)

AppEnv returns a copy of the non-secret env store for app. An app with no env yields an empty map and no error.

func (*Database) AppendAudit

func (d *Database) AppendAudit(ctx context.Context, e controlplane.AuditEntry) error

AppendAudit appends one audit row in append order (the append-only log). It deep-copies the args map so the store never aliases the caller's map, matching a real database.

func (*Database) Audit

Audit returns the rows matching filter, newest first, capped by filter.Limit (a default when unset). The filter clauses are ANDed.

func (*Database) AuditRows

func (d *Database) AuditRows() []controlplane.AuditEntry

AuditRows returns a copy of every appended audit row in append order, for tests asserting on what the engine recorded.

func (*Database) AutoDeployCandidates added in v0.13.0

func (d *Database) AutoDeployCandidates(ctx context.Context) ([]controlplane.AppEnvRef, error)

AutoDeployCandidates returns the distinct (app, environment) pairs that have at least one recorded release, ordered by app then environment for a deterministic reconcile order — the set the pull-based watcher may reconcile (ADR-0052 Phase 4b). An empty stored Environment reads as the canonical "default", matching LatestRelease.

func (*Database) AutoDeployLevel added in v0.13.0

func (d *Database) AutoDeployLevel(ctx context.Context, app, env string) (controlplane.AutoDeployLevel, error)

AutoDeployLevel returns app's auto-deploy level in env, or DefaultAutoDeployLevel (off) when none is set — a missing configuration resolves to the opt-in default, matching the store (ADR-0058).

func (*Database) AutoDeployReason added in v0.13.0

func (d *Database) AutoDeployReason(ctx context.Context, app, env string) (string, error)

AutoDeployReason returns the stored disable reason for app in env, or "" when none is set.

func (*Database) CreateEnvironment added in v0.7.0

func (d *Database) CreateEnvironment(ctx context.Context, name, namespace string) error

CreateEnvironment registers a named environment, rejecting a duplicate name with an ErrInvalid-wrapped error (the name is the primary key), matching the store.

func (*Database) DeleteAddon

func (d *Database) DeleteAddon(ctx context.Context, name string) error

func (*Database) DeleteReleases

func (d *Database) DeleteReleases(ctx context.Context, app string) error

DeleteReleases removes every release record for app, including its save-order tracking. Deleting the releases of an app that has none is a no-op, not an error.

func (*Database) DisableAutoDeploy added in v0.13.0

func (d *Database) DisableAutoDeploy(ctx context.Context, app, env, reason string) error

DisableAutoDeploy sets app's level to off in env and records the reason — the safety stop of ADR-0052 §5, keyed by (app, env).

func (*Database) GetBackup

func (d *Database) GetBackup(ctx context.Context, id string) (controlplane.Backup, error)

GetBackup returns the backup with the given id, or ErrNotFound.

func (*Database) GetEnvironment added in v0.7.0

func (d *Database) GetEnvironment(ctx context.Context, name string) (controlplane.Environment, error)

GetEnvironment returns the registered environment with the given name, or ErrNotFound.

func (*Database) LatestRelease

func (d *Database) LatestRelease(ctx context.Context, app, env string) (controlplane.Release, error)

LatestRelease returns the newest release for app in env — keyed per (app, environment) by filtering the app-global save order on the stored release's Environment (ADR-0052 Phase 4a).

func (*Database) ListBackups

func (d *Database) ListBackups(ctx context.Context, app string) ([]controlplane.Backup, error)

ListBackups returns recorded backups newest first (reverse record order). An empty app lists all.

func (*Database) ListEnvironments added in v0.7.0

func (d *Database) ListEnvironments(ctx context.Context) ([]controlplane.Environment, error)

ListEnvironments returns the registered environments ordered by name. The synthesized `default` environment is not stored here; the engine prepends it.

func (*Database) ListReleases added in v0.13.0

func (d *Database) ListReleases(ctx context.Context, app, env string) ([]controlplane.Release, error)

ListReleases returns every release for app in env, newest first (reverse save order) — the deploy timeline the history surface reads, keyed per (app, environment). An app with no releases in env yields an empty slice and no error.

func (*Database) Policy

func (d *Database) Policy(ctx context.Context) (controlplane.Policy, error)

Policy returns the current guardrail policy.

func (*Database) Provider

func (d *Database) Provider(ctx context.Context, name string) (controlplane.Provider, error)

func (*Database) Providers

func (d *Database) Providers(ctx context.Context) ([]controlplane.Provider, error)

func (*Database) RecordBackup

func (d *Database) RecordBackup(ctx context.Context, b controlplane.Backup) error

RecordBackup persists a new backup row, tracking record order for deterministic listing. An existing row with the same ID is overwritten in place.

func (*Database) Release

func (d *Database) Release(ctx context.Context, id string) (controlplane.Release, error)

func (*Database) Releases

func (d *Database) Releases(ctx context.Context, app, env string) ([]controlplane.Release, error)

Releases returns every release for app in env, oldest first, keyed per (app, environment).

func (*Database) SaveAddon

func (d *Database) SaveAddon(ctx context.Context, a controlplane.AddonInfo) error

SaveAddon upserts an add-on by name. It stores only the non-secret registry entry; Ready is a live property and is not persisted here.

func (*Database) SaveProvider

func (d *Database) SaveProvider(ctx context.Context, p controlplane.Provider) error

SaveProvider upserts a provider by name. It stores only the non-secret registry entry.

func (*Database) SaveRelease

func (d *Database) SaveRelease(ctx context.Context, r controlplane.Release) error

func (*Database) SetAppEnv

func (d *Database) SetAppEnv(ctx context.Context, app, key, value string) error

SetAppEnv upserts one env key for app.

func (*Database) SetAutoDeployLevel added in v0.13.0

func (d *Database) SetAutoDeployLevel(ctx context.Context, app, env string, level controlplane.AutoDeployLevel) error

SetAutoDeployLevel upserts app's auto-deploy level in env, keyed by (app, env). It clears any stored disable reason: setting the level is the deliberate human re-enable action (ADR-0052 §5).

func (*Database) SetBackupStatus

func (d *Database) SetBackupStatus(ctx context.Context, id string, status controlplane.BackupStatus, sizeBytes int64) error

SetBackupStatus updates a recorded backup's status and size. An unknown id is ErrNotFound.

func (*Database) SetError

func (d *Database) SetError(op Op, err error)

SetError makes op return err until cleared with SetError(op, nil).

func (*Database) SetGuardrail

SetGuardrail persists one guardrail's disposition, overlaying it on the current policy.

func (*Database) SetPolicy

func (d *Database) SetPolicy(p controlplane.Policy)

SetPolicy replaces the whole guardrail policy. It is a test helper for arranging a specific policy before exercising the engine.

func (*Database) UnsetAppEnv

func (d *Database) UnsetAppEnv(ctx context.Context, app, key string) error

UnsetAppEnv removes one env key for app. Removing a key that is not set is a no-op.

type IDs

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

IDs is a deterministic controlplane.IDSource that hands out "r1", "r2", ... so tests can predict release identifiers.

func NewIDs

func NewIDs() *IDs

NewIDs returns an ID source starting at r1.

func (*IDs) NewID

func (i *IDs) NewID() string

NewID returns the next sequential identifier.

type Kubernetes

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

Kubernetes is an in-memory controlplane.Kubernetes. Applied workloads are stored and inspectable; by default a workload is healthy (ready == desired) immediately, and tests can override readiness (SetReady) and seed logs (SetLogs) to model partial or failed rollouts. Errors can be injected per operation with SetError.

Per-app resources (workloads, exposures, per-app Secrets) are keyed by namespace so the fake can model namespace-per-environment (ADR-0035 phase 2): WithNamespace returns a view whose app operations land under a different namespace, sharing the same backing maps and lock. The introspection helpers (Spec, SecretValue, …) read the receiver view's namespace; the namespace-qualified variants (SpecInNamespace, SecretValueInNamespace) read a named one.

func NewKubernetes

func NewKubernetes() *Kubernetes

NewKubernetes returns an empty fake cluster. metrics-server is reported present by default (the common case, where an applied HPA scales); a test models a cluster without it via SetMetricsAvailable(false).

func (*Kubernetes) AddonReady

func (k *Kubernetes) AddonReady(ctx context.Context, name string) (bool, error)

AddonReady reports whether the named add-on was deployed (and thus ready) in this fake cluster. A deployed add-on is ready by default; an unknown one is not ready.

func (*Kubernetes) ApplyAutoscaler added in v0.8.0

func (k *Kubernetes) ApplyAutoscaler(ctx context.Context, app string, spec controlplane.AutoscaleSpec) error

func (*Kubernetes) ApplyWorkload

func (k *Kubernetes) ApplyWorkload(ctx context.Context, spec controlplane.WorkloadSpec) error

func (*Kubernetes) Autoscaler added in v0.8.0

func (k *Kubernetes) Autoscaler(app string) (controlplane.AutoscaleSpec, bool)

Autoscaler returns the applied HPA spec for app in this view's namespace and whether one exists — test-only introspection of ApplyAutoscaler/DeleteAutoscaler.

func (*Kubernetes) AutoscalerActive added in v0.8.0

func (k *Kubernetes) AutoscalerActive(ctx context.Context, app string) (bool, error)

AutoscalerActive reports whether app has an applied HPA in this view's namespace — an entry set by ApplyAutoscaler or SetAutoscalerActive and not since deleted. A missing HPA is inactive (false, nil), mirroring the real adapter.

func (*Kubernetes) BackupJobs

func (k *Kubernetes) BackupJobs() []backupCall

BackupJobs returns the (app, backupID) pairs RunBackupJob was called with, in order.

func (*Kubernetes) DeleteAddon

func (k *Kubernetes) DeleteAddon(ctx context.Context, name string) error

func (*Kubernetes) DeleteAutoscaler added in v0.8.0

func (k *Kubernetes) DeleteAutoscaler(ctx context.Context, app string) error

func (*Kubernetes) DeleteWorkload

func (k *Kubernetes) DeleteWorkload(ctx context.Context, app string) error

func (*Kubernetes) DeployAddon

func (*Kubernetes) Expose

func (k *Kubernetes) Expose(ctx context.Context, spec controlplane.ExposeSpec) error

func (*Kubernetes) Exposure

func (k *Kubernetes) Exposure(app string) (controlplane.ExposeSpec, bool)

Exposure returns the recorded exposure for app and whether one exists.

func (*Kubernetes) ExposureStatus

func (k *Kubernetes) ExposureStatus(ctx context.Context, app string) (controlplane.ExposureStatus, error)

func (*Kubernetes) ListWorkloads

func (k *Kubernetes) ListWorkloads(ctx context.Context) ([]controlplane.WorkloadStatus, error)

func (*Kubernetes) Logs

func (*Kubernetes) MetricsAPIAvailable added in v0.8.0

func (k *Kubernetes) MetricsAPIAvailable(ctx context.Context) (bool, error)

func (*Kubernetes) RestartWorkload

func (k *Kubernetes) RestartWorkload(ctx context.Context, app string, at time.Time) error

func (*Kubernetes) RestartedAt

func (k *Kubernetes) RestartedAt(app string) (time.Time, bool)

RestartedAt returns the last RestartWorkload timestamp for app and whether the workload was ever rolled by a restart bump.

func (*Kubernetes) RestoreJobs

func (k *Kubernetes) RestoreJobs() []backupCall

RestoreJobs returns the (app, backupID) pairs RunRestoreJob was called with, in order.

func (*Kubernetes) RunBackupJob

func (k *Kubernetes) RunBackupJob(ctx context.Context, app, backupID string) (int64, error)

func (*Kubernetes) RunJob added in v0.12.0

func (*Kubernetes) RunJobs added in v0.12.0

func (k *Kubernetes) RunJobs() []runCall

RunJobs returns the recorded RunJob invocations, in order, so a test can assert the engine drove the one-off command Job with the app's current image, command, TTL, and target namespace.

func (*Kubernetes) RunRestoreJob

func (k *Kubernetes) RunRestoreJob(ctx context.Context, app, backupID string) error

func (*Kubernetes) ScaleWorkload

func (k *Kubernetes) ScaleWorkload(ctx context.Context, app string, replicas int32) error

func (*Kubernetes) SecretKeys

func (k *Kubernetes) SecretKeys(ctx context.Context, app string) ([]string, error)

func (*Kubernetes) SecretValue

func (k *Kubernetes) SecretValue(app, key string) (string, bool)

SecretValue returns the stored value under key for app in this view's namespace and whether it is present — test-only introspection (the real seam never exposes values).

func (*Kubernetes) SecretValueInNamespace added in v0.7.0

func (k *Kubernetes) SecretValueInNamespace(ns, app, key string) (string, bool)

SecretValueInNamespace is SecretValue scoped to a named namespace, so a test can assert a per-env secret landed in the environment's namespace (ADR-0035 phase 2).

func (*Kubernetes) SetAutoscalerActive added in v0.8.0

func (k *Kubernetes) SetAutoscalerActive(app string, active bool)

SetAutoscalerActive seeds (or clears) an active HorizontalPodAutoscaler for app in this view's namespace, so a test can model an app the autoscaler owns without applying a full AutoscaleSpec through the engine. It shares the backing store with ApplyAutoscaler/DeleteAutoscaler, so both paths agree on what AutoscalerActive reports.

func (*Kubernetes) SetBackupSize

func (k *Kubernetes) SetBackupSize(n int64)

SetBackupSize sets the byte size RunBackupJob reports, modelling the dump container reporting it.

func (*Kubernetes) SetCertReady

func (k *Kubernetes) SetCertReady(app string, ready bool)

SetCertReady sets whether the requested TLS certificate reported for app's exposure has been issued, modelling cert-manager having populated the certificate Secret.

func (*Kubernetes) SetError

func (k *Kubernetes) SetError(op Op, err error)

SetError makes op return err until cleared with SetError(op, nil).

func (*Kubernetes) SetImagePullFailure added in v0.8.0

func (k *Kubernetes) SetImagePullFailure(app, reason string)

SetImagePullFailure models a workload whose pod cannot pull its image: it drops ready to 0 (so the workload is not Available) and records reason as the blocking pod waiting reason, so WorkloadStatus/ListWorkloads report the same actionable Issue the real adapter attaches on a genuine ImagePullBackOff. Pass a non-image-pull reason (or "") to clear it. It is a no-op if app has no workload.

func (*Kubernetes) SetImagePullFailureMessage added in v0.8.0

func (k *Kubernetes) SetImagePullFailureMessage(app, reason, message string)

SetImagePullFailureMessage is SetImagePullFailure with the kubelet's waiting message attached, so a test can drive the not-found vs unauthorized Issue distinction (ADR-0040).

func (*Kubernetes) SetIngressAddress

func (k *Kubernetes) SetIngressAddress(app, addr string)

SetIngressAddress sets the controller-assigned external address reported for app's exposure, modelling the ingress controller having processed the Ingress.

func (*Kubernetes) SetLogs

func (k *Kubernetes) SetLogs(app string, lines []controlplane.LogLine)

SetLogs replaces the stored log lines for app.

func (*Kubernetes) SetMetricsAvailable added in v0.8.0

func (k *Kubernetes) SetMetricsAvailable(available bool)

SetMetricsAvailable sets whether MetricsAPIAvailable reports metrics-server present, modelling a cluster with or without it. It shares the flag across namespace views (like the other pointer state), so a test sets it once on the base fake.

func (*Kubernetes) SetReady

func (k *Kubernetes) SetReady(app string, ready int32)

SetReady overrides the ready replica count for app, modelling a partial rollout. It is a no-op if app has no workload.

func (*Kubernetes) SetRunResult added in v0.12.0

func (k *Kubernetes) SetRunResult(res controlplane.RunResult)

SetRunResult sets the canned RunResult the next RunJob calls return, modelling a command's captured output and exit code (ADR-0048). A test seeds a non-zero ExitCode to assert it surfaces as a structured result rather than a transport error.

func (*Kubernetes) SetSecret

func (k *Kubernetes) SetSecret(app, key, value string)

SetSecret seeds app's per-app Secret with key=value, modelling a `secret set` done over the kubeconfig path (which never goes through this engine seam). Tests use it to set up list/unset.

func (*Kubernetes) SetSecretValue

func (k *Kubernetes) SetSecretValue(ctx context.Context, app, key, value string) error

SetSecretValue upserts key=value into app's per-app Secret map (ADR-0029), modelling burrowd writing the value it received over the control-plane API. SecretKeys/SecretValue read the same map. An OpSetSecretValue error can be injected to exercise the failure path.

func (*Kubernetes) Spec

Spec returns the currently applied spec for app in this view's namespace and whether a workload exists.

func (*Kubernetes) SpecInNamespace added in v0.7.0

func (k *Kubernetes) SpecInNamespace(ns, app string) (controlplane.WorkloadSpec, bool)

SpecInNamespace is Spec scoped to a named namespace, so a test can assert a deploy routed to an environment's namespace (ADR-0035 phase 2).

func (*Kubernetes) Unexpose

func (k *Kubernetes) Unexpose(ctx context.Context, app string) error

func (*Kubernetes) UnsetSecretKey

func (k *Kubernetes) UnsetSecretKey(ctx context.Context, app, key string) error

func (*Kubernetes) WithNamespace added in v0.7.0

func (k *Kubernetes) WithNamespace(ns string) controlplane.Kubernetes

WithNamespace returns a view of the fake whose per-app operations act in ns, sharing the same backing state and lock (ADR-0035 phase 2). Add-on operations are unaffected.

func (*Kubernetes) WorkloadStatus

func (k *Kubernetes) WorkloadStatus(ctx context.Context, app string) (controlplane.WorkloadStatus, error)

type Op

type Op string

Op names a seam method for error injection. Pass one to a fake's SetError to make that method return the given error until it is cleared (SetError(op, nil)).

const (
	OpApply                Op = "ApplyWorkload"
	OpStatus               Op = "WorkloadStatus"
	OpScale                Op = "ScaleWorkload"
	OpLogs                 Op = "Logs"
	OpDelete               Op = "DeleteWorkload"
	OpExpose               Op = "Expose"
	OpUnexpose             Op = "Unexpose"
	OpExposureStatus       Op = "ExposureStatus"
	OpSecretKeys           Op = "SecretKeys"
	OpSetSecretValue       Op = "SetSecretValue"
	OpUnsetSecretKey       Op = "UnsetSecretKey"
	OpRestartWorkload      Op = "RestartWorkload"
	OpApplyAutoscaler      Op = "ApplyAutoscaler"
	OpDeleteAutoscaler     Op = "DeleteAutoscaler"
	OpAutoscalerActive     Op = "AutoscalerActive"
	OpMetricsAPIAvailable  Op = "MetricsAPIAvailable"
	OpAddonReady           Op = "AddonReady"
	OpSaveAddon            Op = "SaveAddon"
	OpAddon                Op = "Addon"
	OpAddons               Op = "Addons"
	OpDeleteAddon          Op = "DeleteAddon"
	OpSaveRelease          Op = "SaveRelease"
	OpRelease              Op = "Release"
	OpLatestRelease        Op = "LatestRelease"
	OpReleases             Op = "Releases"
	OpListReleases         Op = "ListReleases"
	OpDeleteReleases       Op = "DeleteReleases"
	OpAppEnv               Op = "AppEnv"
	OpSetAppEnv            Op = "SetAppEnv"
	OpUnsetAppEnv          Op = "UnsetAppEnv"
	OpPolicy               Op = "Policy"
	OpSetGuardrail         Op = "SetGuardrail"
	OpAutoDeployLevel      Op = "AutoDeployLevel"
	OpSetAutoDeployLevel   Op = "SetAutoDeployLevel"
	OpDisableAutoDeploy    Op = "DisableAutoDeploy"
	OpAutoDeployReason     Op = "AutoDeployReason"
	OpAutoDeployCandidates Op = "AutoDeployCandidates"
	OpSaveProvider         Op = "SaveProvider"
	OpProvider             Op = "Provider"
	OpProviders            Op = "Providers"
	OpToken                Op = "Token"
	OpSetToken             Op = "SetToken"
	OpDNS                  Op = "DNS"
	OpVerifyAccess         Op = "VerifyAccess"
	OpAppendAudit          Op = "AppendAudit"
	OpAudit                Op = "Audit"
	OpRecordBackup         Op = "RecordBackup"
	OpSetBackupStatus      Op = "SetBackupStatus"
	OpListBackups          Op = "ListBackups"
	OpGetBackup            Op = "GetBackup"
	OpRunBackupJob         Op = "RunBackupJob"
	OpRunRestoreJob        Op = "RunRestoreJob"
	OpRunJob               Op = "RunJob"

	OpCreateEnvironment Op = "CreateEnvironment"
	OpListEnvironments  Op = "ListEnvironments"
	OpGetEnvironment    Op = "GetEnvironment"
)

type Provisioner

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

Provisioner is an in-memory controlplane.DatabaseProvisioner. It records the apps it provisioned and returns a deterministic connection string per app, so an attach test can assert the engine called EnsureAppDatabase and threaded the URL into the secret path without standing up Postgres. Errors can be injected to exercise the failure path.

func NewProvisioner

func NewProvisioner() *Provisioner

NewProvisioner returns an empty fake provisioner.

func (*Provisioner) DropAppDatabase

func (p *Provisioner) DropAppDatabase(_ context.Context, app string) error

func (*Provisioner) Dropped

func (p *Provisioner) Dropped() []string

Dropped returns the apps DropAppDatabase was called with, in order.

func (*Provisioner) EnsureAppDatabase

func (p *Provisioner) EnsureAppDatabase(_ context.Context, app string) (string, error)

func (*Provisioner) Ensured

func (p *Provisioner) Ensured() []string

Ensured returns the apps EnsureAppDatabase was called with, in order.

func (*Provisioner) SetDropError

func (p *Provisioner) SetDropError(err error)

SetDropError makes DropAppDatabase return err (nil clears it).

func (*Provisioner) SetEnsureError

func (p *Provisioner) SetEnsureError(err error)

SetEnsureError makes EnsureAppDatabase return err (nil clears it).

type Registry

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

Registry is an in-memory controlplane.RegistryClient. Tests seed the tag list it returns with SetTags, read back the last imageRef and auth it was called with, and inject a failure with SetError, so the auto-deploy read/watch path can be exercised against a known tag set and against a registry failure without a real registry. Tags and errors can also be set PER imageRef (SetTagsFor / SetErrorFor) so a multi-app poll pass can give one app a failure while another lists cleanly — the isolation the fault-injection tests assert.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty fake registry client.

func (*Registry) Calls added in v0.13.0

func (r *Registry) Calls() int

Calls returns how many times ListTags has been called.

func (*Registry) LastAuth added in v0.13.0

func (r *Registry) LastAuth() controlplane.RegistryAuth

LastAuth returns the auth ListTags was last called with — a test asserts the read path lists anonymously (the zero value) in this phase.

func (*Registry) LastRef added in v0.13.0

func (r *Registry) LastRef() string

LastRef returns the imageRef ListTags was last called with.

func (*Registry) ListTags added in v0.13.0

func (r *Registry) ListTags(_ context.Context, imageRef string, auth controlplane.RegistryAuth) ([]string, error)

func (*Registry) SetError

func (r *Registry) SetError(err error)

SetError makes ListTags return err for any ref without a per-ref override (nil clears it).

func (*Registry) SetErrorFor added in v0.13.0

func (r *Registry) SetErrorFor(ref string, err error)

SetErrorFor makes ListTags return err for a specific imageRef, taking precedence over the default error — so a fault can be injected for one app while another lists cleanly (nil clears it).

func (*Registry) SetTags added in v0.13.0

func (r *Registry) SetTags(tags ...string)

SetTags seeds the tags ListTags returns for any ref without a per-ref override.

func (*Registry) SetTagsFor added in v0.13.0

func (r *Registry) SetTagsFor(ref string, tags ...string)

SetTagsFor seeds the tags ListTags returns for a specific imageRef, taking precedence over the default set. It lets one poll pass return different tags per app.

type Resolver

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

Resolver is an in-memory controlplane.Resolver. Seed what a host resolves to with Set; an unseeded host returns an error, modelling NXDOMAIN.

func NewResolver

func NewResolver() *Resolver

NewResolver returns a resolver that knows no hosts.

func (*Resolver) LookupHost

func (r *Resolver) LookupHost(ctx context.Context, host string) ([]string, error)

func (*Resolver) Set

func (r *Resolver) Set(host string, addrs ...string)

Set makes host resolve to addrs.

func (*Resolver) SetError

func (r *Resolver) SetError(err error)

SetError makes every lookup return err until cleared with SetError(nil).

Jump to

Keyboard shortcuts

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