testutil

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildChart

func BuildChart(opts ...ChartOption) *helmchart.Chart

BuildChart returns a Helm chart object built with basic data and any provided chart options.

func BuildChartWithSubchartWithCRD added in v1.2.0

func BuildChartWithSubchartWithCRD() *helmchart.Chart

BuildChartWithSubchartWithCRD returns a Helm chart object with a subchart that contains a CRD. Useful for testing helm-controller's staged CRDs-first deployment logic.

func BuildRelease

func BuildRelease(mockOpts *helmrelease.MockReleaseOptions, opts ...ReleaseOption) *helmrelease.Release

BuildRelease builds a release with release.Mock using the given options, and applies any provided options to the release before returning it.

func Equal

func Equal(expected any, options ...cmp.Option) types.GomegaMatcher

Equal uses go-cmp to compare actual with expected. Equal is strict about types when performing comparisons.

func MustParseHelmTime

func MustParseHelmTime(t string) time.Time

MustParseHelmTime parses a string into a Helm time.Time, panicking if it fails.

func NewMockResourceManagerFunc added in v1.5.0

func NewMockResourceManagerFunc() func(sr ...newStatusReaderFunc) *ssa.ResourceManager

NewMockResourceManagerFunc returns a function compatible with action.WithResourceManager using a new MockStatusReader.

func SaveChart

func SaveChart(c *chart.Chart, outDir string) (string, error)

SaveChart saves the given chart to the given directory, and returns the path to the saved chart. The chart is saved with a random suffix to avoid name collisions.

func SaveChartAsArtifact

func SaveChartAsArtifact(c *chart.Chart, algo digest.Algorithm, baseURL, outDir string) (*meta.Artifact, error)

SaveChartAsArtifact saves the given chart to the given directory, and returns an artifact with the chart's metadata. The chart is saved with a random suffix to avoid name collisions.

Types

type ChartOption

type ChartOption func(*ChartOptions)

ChartOption is a function that can be used to modify a chart.

func ChartWithCRD added in v1.2.0

func ChartWithCRD() ChartOption

ChartWithCRD appends a CRD to the chart.

func ChartWithDependency added in v1.2.0

func ChartWithDependency(md *helmchart.Dependency, chrt *helmchart.Chart) ChartOption

ChartWithDependency appends a dependency to the chart.

func ChartWithFailingDeployment added in v1.5.0

func ChartWithFailingDeployment() ChartOption

ChartWithFailingDeployment appends a deployment with a non-existent image to the chart. This is useful for testing health check timeout and cancellation scenarios.

func ChartWithFailingHook

func ChartWithFailingHook() ChartOption

ChartWithFailingHook appends a failing hook to the chart.

func ChartWithFailingTestHook

func ChartWithFailingTestHook() ChartOption

ChartWithFailingTestHook appends a failing test hook to the chart.

func ChartWithManifestWithCustomName added in v1.2.0

func ChartWithManifestWithCustomName(name string) ChartOption

ChartWithManifestWithCustomName sets the name of the manifest.

func ChartWithName

func ChartWithName(name string) ChartOption

ChartWithName sets the name of the chart.

func ChartWithTestHook

func ChartWithTestHook() ChartOption

ChartWithTestHook appends a test hook to the chart.

func ChartWithValues added in v1.2.0

func ChartWithValues(values map[string]any) ChartOption

ChartWithValues sets the values.yaml file of the chart.

func ChartWithVersion

func ChartWithVersion(version string) ChartOption

ChartWithVersion sets the version of the chart.

type ChartOptions

type ChartOptions struct {
	*helmchart.Chart
}

ChartOptions is a helper to build a Helm chart object.

type FakeRecorder

type FakeRecorder struct {
	Events        chan corev1.Event
	IncludeObject bool
}

FakeRecorder is used as a fake during tests.

It was invented to be used in tests which require more precise control over e.g. assertions of specific event fields like Reason. For which string comparisons on the concentrated event message using record.FakeRecorder is not sufficient.

To empty the Events channel into a slice of the recorded events, use GetEvents(). Not initializing Events will cause the recorder to not record any messages.

func NewFakeRecorder

func NewFakeRecorder(bufferSize int, includeObject bool) *FakeRecorder

NewFakeRecorder creates new fake event recorder with an Events channel with the given size. Setting includeObject to true will cause the recorder to include the object reference in the events.

To initialize a recorder which does not record any events, simply use:

recorder := new(FakeRecorder)

func (*FakeRecorder) AnnotatedEventf

func (f *FakeRecorder) AnnotatedEventf(obj runtime.Object, annotations map[string]string, eventType, reason, message string, args ...any)

AnnotatedEventf emits an event with annotations.

func (*FakeRecorder) Event

func (f *FakeRecorder) Event(obj runtime.Object, eventType, reason, message string)

Event emits an event with the given message.

func (*FakeRecorder) Eventf

func (f *FakeRecorder) Eventf(obj runtime.Object, eventType, reason, message string, args ...any)

Eventf emits an event with the given message.

func (*FakeRecorder) GetEvents

func (f *FakeRecorder) GetEvents() (events []corev1.Event)

GetEvents empties the Events channel and returns a slice of recorded events. If the Events channel is nil, it returns nil.

type MockSLogHandler added in v1.5.0

type MockSLogHandler struct {
	Called bool
}

MockSLogHandler lets callers know if Handle was called.

func (*MockSLogHandler) Enabled added in v1.5.0

Enabled implements slog.Handler.

func (*MockSLogHandler) Handle added in v1.5.0

Handle implements slog.Handler.

func (*MockSLogHandler) WithAttrs added in v1.5.0

func (m *MockSLogHandler) WithAttrs(attrs []slog.Attr) slog.Handler

WithAttrs implements slog.Handler.

func (*MockSLogHandler) WithGroup added in v1.5.0

func (m *MockSLogHandler) WithGroup(name string) slog.Handler

WithGroup implements slog.Handler.

type MockStatusReader added in v1.5.0

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

MockStatusReader is a mock implementation of engine.StatusReader that returns a healthy status for all resources and tracks method calls.

func (*MockStatusReader) NewResourceManagerFunc added in v1.5.0

func (m *MockStatusReader) NewResourceManagerFunc() func(sr ...newStatusReaderFunc) *ssa.ResourceManager

NewResourceManagerFunc returns a function compatible with action.WithResourceManager that uses this MockStatusReader as a custom status reader in the returned ResourceManager.

func (*MockStatusReader) NewResourceManagerFuncWithClient added in v1.5.0

func (m *MockStatusReader) NewResourceManagerFuncWithClient(c client.Client, mapper apimeta.RESTMapper) func(sr ...newStatusReaderFunc) *ssa.ResourceManager

NewResourceManagerFuncWithClient returns a function compatible with action.WithResourceManager that uses this MockStatusReader with a real client and REST mapper for the poller engine.

func (*MockStatusReader) ReadStatus added in v1.5.0

ReadStatus returns a Current status for any resource.

func (*MockStatusReader) ReadStatusForObject added in v1.5.0

ReadStatusForObject returns a Current status for any object and records the call.

func (*MockStatusReader) ReadStatusForObjectCalled added in v1.5.0

func (m *MockStatusReader) ReadStatusForObjectCalled() int

ReadStatusForObjectCalled returns the number of times ReadStatusForObject was called.

func (*MockStatusReader) Supports added in v1.5.0

func (m *MockStatusReader) Supports(gk schema.GroupKind) bool

Supports returns true for all GroupKinds and records the call.

func (*MockStatusReader) SupportsCalled added in v1.5.0

func (m *MockStatusReader) SupportsCalled() int

SupportsCalled returns the number of times Supports was called.

type ReleaseOption

type ReleaseOption func(*ReleaseOptions)

ReleaseOption is a function that can be used to modify a release.

func ReleaseWithConfig

func ReleaseWithConfig(config map[string]any) ReleaseOption

ReleaseWithConfig sets the config on the release.

func ReleaseWithFailingHook

func ReleaseWithFailingHook() ReleaseOption

ReleaseWithFailingHook appends a failing hook to the release.

func ReleaseWithFailingTestHook

func ReleaseWithFailingTestHook() ReleaseOption

ReleaseWithFailingTestHook appends a failing test hook to the release.

func ReleaseWithHookExecution

func ReleaseWithHookExecution(name string, events []helmrelease.HookEvent, phase helmrelease.HookPhase) ReleaseOption

ReleaseWithHookExecution appends a hook with a last run with the given execution phase on the release.

func ReleaseWithHooks

func ReleaseWithHooks(hooks []*helmrelease.Hook) ReleaseOption

ReleaseWithHooks sets the hooks on the release.

func ReleaseWithLabels

func ReleaseWithLabels(labels map[string]string) ReleaseOption

ReleaseWithLabels sets the labels on the release.

func ReleaseWithTestHook

func ReleaseWithTestHook() ReleaseOption

ReleaseWithTestHook appends a test hook to the release.

type ReleaseOptions

type ReleaseOptions struct {
	*helmrelease.Release
}

ReleaseOptions is a helper to build a Helm release mock.

Jump to

Keyboard shortcuts

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