Documentation
¶
Index ¶
- func AssertEqual(t *gt.T, want, actual any, description string, opts ...DiffOption)
- func Colorize(diff string) string
- func SetResourceBuilderBaseDir(dir string)
- type Args
- type Case
- type DiffOption
- type FunctionResult
- type GoldenFileCase
- type ResourceBuilder
- func (b *ResourceBuilder) ToStruct() *structpb.Struct
- func (b *ResourceBuilder) WithStatus(status map[string]any) *ResourceBuilder
- func (b *ResourceBuilder) WithStatusConditions(conditions ...xpv2.Condition) *ResourceBuilder
- func (b *ResourceBuilder) WithoutName() *ResourceBuilder
- func (b *ResourceBuilder) WithoutStatus() *ResourceBuilder
- type RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) Build() *fnv1.RunFunctionRequest
- func (b *RunFunctionRequestBuilder) WithInput(input *ResourceBuilder) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) WithMetaTag(tag string) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) WithObservedComposite(composite *ResourceBuilder) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) WithObservedResource(name string, resource *ResourceBuilder, ready ...fnv1.Ready) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) WithRequiredResources(name string, resources ...*structpb.Struct) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) Woc(composite *ResourceBuilder) *RunFunctionRequestBuilder
- func (b *RunFunctionRequestBuilder) Wor(name string, resource *ResourceBuilder, ready ...fnv1.Ready) *RunFunctionRequestBuilder
- type RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) Build() *fnv1.RunFunctionResponse
- func (b *RunFunctionResponseBuilder) Wdr(name string, res *ResourceBuilder, ready ...fnv1.Ready) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithCondition(type_ string, status fnv1.Status, reason string, target fnv1.Target) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithDesiredComposite(composite *structpb.Struct) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithDesiredResource(name string, res *ResourceBuilder, ready ...fnv1.Ready) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithMetaTag(tag string) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithNormalResult(message string) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithRequiredResources(name string, selector *fnv1.ResourceSelector) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithResult(severity fnv1.Severity, message string, target fnv1.Target) *RunFunctionResponseBuilder
- func (b *RunFunctionResponseBuilder) WithTTL(duration time.Duration) *RunFunctionResponseBuilder
- type Want
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 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
}
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 ¶
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 ¶
func (b *RunFunctionRequestBuilder) Build() *fnv1.RunFunctionRequest
Build returns the constructed RunFunctionRequest.
func (*RunFunctionRequestBuilder) WithInput ¶
func (b *RunFunctionRequestBuilder) WithInput(input *ResourceBuilder) *RunFunctionRequestBuilder
WithInput sets the input resource.
func (*RunFunctionRequestBuilder) WithMetaTag ¶
func (b *RunFunctionRequestBuilder) WithMetaTag(tag string) *RunFunctionRequestBuilder
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 ¶
func (b *RunFunctionRequestBuilder) Woc( composite *ResourceBuilder, ) *RunFunctionRequestBuilder
Woc adds an observed composite resource.
func (*RunFunctionRequestBuilder) Wor ¶
func (b *RunFunctionRequestBuilder) Wor( name string, resource *ResourceBuilder, ready ...fnv1.Ready, ) *RunFunctionRequestBuilder
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 ¶
func (b *RunFunctionResponseBuilder) Build() *fnv1.RunFunctionResponse
Build returns the constructed RunFunctionResponse.
func (*RunFunctionResponseBuilder) Wdr ¶
func (b *RunFunctionResponseBuilder) Wdr( name string, res *ResourceBuilder, ready ...fnv1.Ready, ) *RunFunctionResponseBuilder
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 ¶
func (b *RunFunctionResponseBuilder) WithMetaTag(tag string) *RunFunctionResponseBuilder
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 ¶
func (b *RunFunctionResponseBuilder) WithTTL(duration time.Duration) *RunFunctionResponseBuilder
WithTTL sets the TTL in the response meta.
type Want ¶
type Want struct {
Rsp *fnv1.RunFunctionResponse
Err error
}
Want function response and error.