testutil

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testutil is shared fixture scaffolding for tests across the repo — kept minimal so each test file stays self-describing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DepRefs

func DepRefs(ids ...manifest.NamedResource) []manifest.DependencyRef

DepRefs wraps NamedResources as bare DependencyRefs (no ReadyExpr), the shape dependency-ordering tests use to express dependsOn edges.

func MustYAML

func MustYAML(t testing.TB, doc string) map[string]any

MustYAML decodes a single YAML document literal into a generic map, failing the test on parse error or multi-document input.

func NewStoreWithStatuses

func NewStoreWithStatuses(statuses map[manifest.NamedResource]store.Status) *store.Store

NewStoreWithStatuses returns a fresh Store with each id pre-set to the given status (empty message), collapsing the store.New() + per-id UpdateStatus boilerplate common to dependency and render tests that need a pre-populated store.

func SelfSignedCA

func SelfSignedCA(t *testing.T) string

SelfSignedCA returns a PEM-encoded CA certificate.

func SelfSignedClientCert

func SelfSignedClientCert(t *testing.T) (cert, key string)

SelfSignedClientCert returns a PEM-encoded client cert and matching ECDSA private key — ExtKeyUsage is ClientAuth only.

func SelfSignedServerCert

func SelfSignedServerCert(t *testing.T) (cert, key string)

SelfSignedServerCert returns a PEM-encoded server+client cert and matching ECDSA private key — usable as both a TLS server cert and a CA bundle (IsCA=true).

func WaitForStatus

func WaitForStatus(t *testing.T, st *store.Store, id manifest.NamedResource, want store.Status) store.StatusInfo

WaitForStatus polls st until id reaches want status or a 2-second deadline expires. It is the shared polling helper used by controller tests (helmrelease, kustomization, source) to avoid identical inline copies in each package.

func WriteFile

func WriteFile(t testing.TB, root, rel, body string)

WriteFile writes body to root/rel, creating any missing parent directories. Fails the test on any I/O error.

Accepts testing.TB so benchmarks (*testing.B) can share the same fixture helper as unit tests (*testing.T) — fixture building is part of the bench's setup phase, not the measured loop.

func WriteFileAt

func WriteFileAt(t testing.TB, path, body string)

WriteFileAt writes body to path (absolute or cwd-relative), creating any missing parent directories. Companion to WriteFile for callers that already hold a full path rather than a root+rel split.

Types

type MapLister

MapLister is a test fixture that implements change.ObjectLister via a plain map. Used by controller tests that need a minimal ObjectLister (typically an empty one) to construct a change.Filter.

func EmptyLister

func EmptyLister() MapLister

EmptyLister returns a MapLister with no entries — a minimal non-nil ObjectLister for tests that only need to construct a change.Filter.

func (MapLister) GetObject

GetObject returns the manifest stored under id, or nil if absent.

func (MapLister) ListObjects

func (m MapLister) ListObjects(kind string) []manifest.BaseManifest

ListObjects returns all manifests whose kind matches the given string.

Jump to

Keyboard shortcuts

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