testutil

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 43 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 CopyTree added in v0.7.3

func CopyTree(tb testing.TB, src, dst string)

CopyTree copies src into dst using fixture directory and file modes.

func CrossSourceOptionalInputs added in v0.7.3

func CrossSourceOptionalInputs(tb testing.TB) [2]string

CrossSourceOptionalInputs creates identical bootstrap trees with distinct local selected-source histories.

func Declarations added in v0.7.3

func Declarations(productions []manifest.Production) []manifest.NamedResource

Declarations returns sorted unique declarations from borrowed production evidence.

func DecodeDocs added in v0.7.3

func DecodeDocs(r io.Reader) ([]map[string]any, error)

DecodeDocs constructs mapping fixtures and rejects retained failures.

func DecodeRender added in v0.7.3

func DecodeRender(data []byte) ([]map[string]any, error)

DecodeRender projects constructed cache fixtures.

func DocumentMaps added in v0.7.3

func DocumentMaps(docs []manifest.DocOccurrence) []map[string]any

DocumentMaps projects attempted inventory for mapping assertions.

func DocumentOccurrences added in v0.7.3

func DocumentOccurrences(docs []map[string]any) []manifest.DocOccurrence

DocumentOccurrences assigns ordinals to mapping fixtures.

func EncodeRender added in v0.7.3

func EncodeRender(docs []map[string]any) ([]byte, error)

EncodeRender encodes ordered mapping fixtures.

func GitCommitAll added in v0.7.3

func GitCommitAll(tb testing.TB, repo *git.Repository, message string, options *git.CommitOptions) plumbing.Hash

GitCommitAll stages the entire worktree and commits it with the supplied options.

func GitInit added in v0.7.3

func GitInit(tb testing.TB, dir string) *git.Repository

GitInit initializes a Git repository at dir.

func HelmReleaseID added in v0.7.3

func HelmReleaseID(namespace, name string) manifest.NamedResource

HelmReleaseID returns the identity of a Flux HelmRelease.

func KustomizationID added in v0.7.3

func KustomizationID(namespace, name string) manifest.NamedResource

KustomizationID returns the identity of a Flux Kustomization.

func KustomizationYAML added in v0.7.3

func KustomizationYAML(name, namespace, spec string) string

KustomizationYAML wraps spec in a Flux Kustomization document.

func ObjectDocument added in v0.7.3

func ObjectDocument(obj manifest.BaseManifest) map[string]any

ObjectDocument retains data payloads when constructing authoritative SDK fixtures.

func Owners added in v0.7.3

func Owners(productions []manifest.Production) []manifest.NamedResource

Owners returns sorted unique owners from borrowed production evidence.

func ProductionEvidence added in v0.7.3

func ProductionEvidence(ids []manifest.NamedResource) []manifest.Production

ProductionEvidence supplies fixture ownership without authored coordinates.

func RenderMaps added in v0.7.3

func RenderMaps(
	docs []manifest.DocOccurrence,
	receipt *manifest.RenderReceipt,
	err error,
) ([]map[string]any, *manifest.RenderReceipt, error)

RenderMaps projects successful renderer outcomes for map assertions.

func SelfSignedCA

func SelfSignedCA(t *testing.T) string

SelfSignedCA returns a PEM-encoded CA certificate.

func SplitDocs added in v0.7.3

func SplitDocs(data []byte) ([]map[string]any, error)

SplitDocs constructs mapping fixtures from bytes.

func StubDNS added in v0.7.3

func StubDNS(t *testing.T, lookup func(context.Context, string) error)

StubDNS bypasses environment proxies and resolves fixture hosts to loopback or a lookup error. It changes process-global state, so callers MUST remain serial.

func TarGz added in v0.7.3

func TarGz(tb testing.TB, files map[string]string, mode int64, level int) []byte

TarGz returns regular files compressed at level in name order.

func WriteFile

func WriteFile(tb 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(tb 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.

func WriteFilteredOrderingCluster added in v0.7.3

func WriteFilteredOrderingCluster(tb testing.TB, root, greeting string, brokenSource bool)

WriteFilteredOrderingCluster applies required sources beside excluded controllers and sources.

func WriteGeneratedValuesCluster added in v0.7.3

func WriteGeneratedValuesCluster(tb testing.TB, root string)

WriteGeneratedValuesCluster creates two ordered releases using a generated values ConfigMap.

func WriteSubstitutionProducerCluster added in v0.7.3

func WriteSubstitutionProducerCluster(tb testing.TB, root, kind string)

WriteSubstitutionProducerCluster creates a generator whose rendered data differs from discovery.

func WriteTar added in v0.7.3

func WriteTar(tb testing.TB, dst io.Writer, files map[string]string, mode int64)

WriteTar writes regular files in name order with the supplied mode.

func WriteTree added in v0.7.3

func WriteTree(tb testing.TB, files map[string]string) string

WriteTree writes files beneath a symlink-resolved temporary directory.

Types

type Certificate added in v0.7.3

type Certificate struct{ Cert, Key string }

Certificate keeps a PEM certificate with its matching private key.

func SelfSignedClientCert

func SelfSignedClientCert(t *testing.T) Certificate

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

func SelfSignedServerCert

func SelfSignedServerCert(t *testing.T) Certificate

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).

type ChartRegistry added in v0.7.3

type ChartRegistry struct {
	URL, Digest   string
	Authenticated atomic.Int64
	Digests       []string
	TagGeneration atomic.Int64
	Requests      atomic.Uint64
}

ChartRegistry serves chart layers from an in-process TLS registry.

func NewChartRegistry added in v0.7.3

func NewChartRegistry(t *testing.T, files []map[string]string, auth bool) *ChartRegistry

NewChartRegistry returns a local OCI registry with fixed chart contents.

type CountingStorer added in v0.7.3

type CountingStorer struct {
	storage.Storer

	Reads *GitReads
}

CountingStorer preserves storage behavior while counting object Reader opens.

func (*CountingStorer) EncodedObject added in v0.7.3

func (s *CountingStorer) EncodedObject(kind plumbing.ObjectType, hash plumbing.Hash) (plumbing.EncodedObject, error)

EncodedObject wraps readers without changing their type, identity or bytes.

type GitReads added in v0.7.3

type GitReads struct {
	Metadata, Bodies, Large atomic.Int64
	LargeHash               plumbing.Hash
}

GitReads separates metadata Reader opens from blob Reader opens in one phase.

func (*GitReads) Reset added in v0.7.3

func (r *GitReads) Reset()

Reset starts a new observation phase after all prior readers have stopped.

type SparseGit added in v0.7.3

type SparseGit struct {
	Root              string
	Repo              *git.Repository
	Base, Head, Large plumbing.Hash
}

SparseGit retains the two committed snapshots of the E8 sparse workload.

func NewSparseGit added in v0.7.3

func NewSparseGit(tb testing.TB, files int, blobBytes int64) SparseGit

NewSparseGit writes exactly files committed files, streaming the unrelated blob.

Directories

Path Synopsis
Package cachetest provides constructor-injected cache fixtures.
Package cachetest provides constructor-injected cache fixtures.
Package controllertest drives controller fixtures through their task service.
Package controllertest drives controller fixtures through their task service.
Package fetchtest preserves the two acquisition phases in source tests.
Package fetchtest preserves the two acquisition phases in source tests.

Jump to

Keyboard shortcuts

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