testing

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEqual

func AssertEqual(t *gt.T, want, actual any, description string, opts ...DiffOption)

AssertEqual asserts that two values are equal. Values are converted to YAML before comparison, differences are represented as colored diff.

func Colorize

func Colorize(diff string) string

Colorize returns a string with colorized diff.

func SetResourceBuilderBaseDir

func SetResourceBuilderBaseDir(dir string)

SetResourceBuilderBaseDir defines the base directory path used for resource building operations.

Types

type Args

type Args struct {
	Ctx context.Context //nolint:containedctx // ok for this test case
	Req *fnv1.RunFunctionRequest
}

Args function request arguments.

type Case

type Case struct {
	// Reason is a human-readable description of the test case.
	Reason string
	// Args are the arguments available in the request for the test case.
	Args Args
	// Want is the expected response for the test case.
	Want Want
	// HookFunction is an optional function that can be run before/after the test case is run.
	HookFunction func()
	// DiffOptions are the diff options for the test case.
	DiffOptions []DiffOption
	// Parallel run test casse n times parallel
	Parallel int
	// Results the expected results returned by the function. Empty of OK
	Results []FunctionResult
}

func (*Case) Run

func (c *Case) Run(tb gt.TB, f fnv1.FunctionRunnerServiceServer)

Run runs the function test case.

type DiffOption

type DiffOption func(opts *diff)

func Granular

func Granular() DiffOption

Granular if enabled, diff is evaluated on individual response parts as yaml, rather dnt on the whole structpb response object.

func WithDiffContextLines

func WithDiffContextLines(lines int) DiffOption

WithDiffContextLines sets the number of context lines to use when diffing YAML.

func WithYamlIndent

func WithYamlIndent(indent int) DiffOption

WithYamlIndent sets the YAML indentation level.

type FunctionResult

type FunctionResult struct {
	Severity fnv1.Severity
	Message  string
}

FunctionResult is the result of a function execution.

type GoldenFileCase

type GoldenFileCase struct {
	// Reason is a human-readable description of the test case.
	Reason string
	// Composite the path ot the composite file to use for this test
	Composite string
	// Observed resources to mapped by their key used as observed resources in the function request
	Observed map[string]string
	// Required resources to mapped by their key used as required resources in the function request
	Required map[string]string
	// Input the function input file for the request
	Input string
	// DesiredLocation location of the desired files used to verif the output or the function
	DesiredLocation string
	// WithReady whether to verify the ready result of the desired resources in the function response.
	WithReady bool
	// Err the expected error returned by the function.
	Err error
	// Results the expected results returned by the function. Empty of OK
	Results []FunctionResult

	// DiffOptions are the diff options for the test case.
	DiffOptions []DiffOption
	// contains filtered or unexported fields
}

func (*GoldenFileCase) Run

func (c *GoldenFileCase) Run(tb gt.TB, caseName string, f fnv1.FunctionRunnerServiceServer)

Run runs the function test case.

type ResourceBuilder

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

ResourceBuilder Reads an initial resource from a YAML file and optionally adds status/conditions to it.

func From

func From(file string) *ResourceBuilder

From Returns a new Resource Builder from a given file.

func NewResourceFromFile

func NewResourceFromFile(file string) *ResourceBuilder

NewResourceFromFile Returns a new Resource Builder.

func (*ResourceBuilder) ToStruct

func (b *ResourceBuilder) ToStruct() *structpb.Struct

ToStruct returns a structpb.Struct object out of the initially provided configurations Function panics on error. To be used in tests only!

func (*ResourceBuilder) WithStatus

func (b *ResourceBuilder) WithStatus(status map[string]any) *ResourceBuilder

WithStatus sets optional status values in the resource.

func (*ResourceBuilder) WithStatusConditions

func (b *ResourceBuilder) WithStatusConditions(conditions ...xpv2.Condition) *ResourceBuilder

WithStatusConditions adds conditions Example: WithStatusConditions(xpv2.Available(), xpv2.ReconcileSuccess()).

func (*ResourceBuilder) WithoutName

func (b *ResourceBuilder) WithoutName() *ResourceBuilder

WithoutName removes the metadata.name from the object, mainly used for desired resources as we do not expect any name.

func (*ResourceBuilder) WithoutStatus

func (b *ResourceBuilder) WithoutStatus() *ResourceBuilder

WithoutStatus removes the status from the object, mainly used for desired resources as we do not expect any status.

type RunFunctionRequestBuilder

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

RunFunctionRequestBuilder helps build RunFunctionRequest objects.

func NewRequestBuilder

func NewRequestBuilder() *RunFunctionRequestBuilder

NewRequestBuilder creates a new builder instance.

func (*RunFunctionRequestBuilder) Build

Build returns the constructed RunFunctionRequest.

func (*RunFunctionRequestBuilder) WithInput

WithInput sets the input resource.

func (*RunFunctionRequestBuilder) WithMetaTag

WithMetaTag adds a meta tag.

func (*RunFunctionRequestBuilder) WithObservedComposite

func (b *RunFunctionRequestBuilder) WithObservedComposite(
	composite *ResourceBuilder,
) *RunFunctionRequestBuilder

WithObservedComposite adds an observed composite resource.

func (*RunFunctionRequestBuilder) WithObservedResource

func (b *RunFunctionRequestBuilder) WithObservedResource(
	name string,
	resource *ResourceBuilder,
	ready ...fnv1.Ready,
) *RunFunctionRequestBuilder

WithObservedResource adds an observed resource with the given name.

func (*RunFunctionRequestBuilder) WithRequiredResources

func (b *RunFunctionRequestBuilder) WithRequiredResources(
	name string,
	resources ...*structpb.Struct,
) *RunFunctionRequestBuilder

WithRequiredResources adds required resources with the given name.

func (*RunFunctionRequestBuilder) Woc

Woc adds an observed composite resource.

func (*RunFunctionRequestBuilder) Wor

Wor adds an observed resource with the given name.

type RunFunctionResponseBuilder

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

RunFunctionResponseBuilder helps build RunFunctionResponse objects.

func NewResponseBuilder

func NewResponseBuilder() *RunFunctionResponseBuilder

NewResponseBuilder creates a new builder instance.

func (*RunFunctionResponseBuilder) Build

Build returns the constructed RunFunctionResponse.

func (*RunFunctionResponseBuilder) Wdr

Wdr adds a desired resource with the given name.

func (*RunFunctionResponseBuilder) WithCondition

func (b *RunFunctionResponseBuilder) WithCondition(
	type_ string,
	status fnv1.Status,
	reason string,
	target fnv1.Target,
) *RunFunctionResponseBuilder

WithCondition adds a condition to the response.

func (*RunFunctionResponseBuilder) WithDesiredComposite

func (b *RunFunctionResponseBuilder) WithDesiredComposite(
	composite *structpb.Struct,
) *RunFunctionResponseBuilder

WithDesiredComposite sets the desired composite resource.

func (*RunFunctionResponseBuilder) WithDesiredResource

func (b *RunFunctionResponseBuilder) WithDesiredResource(
	name string,
	res *ResourceBuilder,
	ready ...fnv1.Ready,
) *RunFunctionResponseBuilder

WithDesiredResource adds a desired resource with the given name.

func (*RunFunctionResponseBuilder) WithMetaTag

WithMetaTag adds a meta tag.

func (*RunFunctionResponseBuilder) WithNormalResult

func (b *RunFunctionResponseBuilder) WithNormalResult(message string) *RunFunctionResponseBuilder

WithNormalResult adds a normal severity result.

func (*RunFunctionResponseBuilder) WithRequiredResources

func (b *RunFunctionResponseBuilder) WithRequiredResources(
	name string,
	selector *fnv1.ResourceSelector,
) *RunFunctionResponseBuilder

WithRequiredResources adds extra resources with the given name.

func (*RunFunctionResponseBuilder) WithResult

func (b *RunFunctionResponseBuilder) WithResult(
	severity fnv1.Severity,
	message string,
	target fnv1.Target,
) *RunFunctionResponseBuilder

WithResult adds a result to the response.

func (*RunFunctionResponseBuilder) WithTTL

WithTTL sets the TTL in the response meta.

type Want

type Want struct {
	Rsp *fnv1.RunFunctionResponse
	Err error
}

Want function response and error.

Jump to

Keyboard shortcuts

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