testing

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const AnnotationKeyResourceName = "fn-server.test/resource-name"

AnnotationKeyResourceName is the key of the annotation that defines the resource name.

Variables

This section is empty.

Functions

This section is empty.

Types

type FunctionTest

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

func TestFunction

func TestFunction(t *testing.T, fn server.ServerFunction, opts ...TestFunctionOpt) *FunctionTest

func (*FunctionTest) Run

func (t *FunctionTest) Run(ctx context.Context)

type ResourceModifier

type ResourceModifier func(res *fnapi.Resource)

ResourceModifier modifies a fnapi.Resource.

func WithConnectionDetails

func WithConnectionDetails(cd map[string][]byte) ResourceModifier

WithConnectionDetails sets the connection details of an fnapi.Resource.

func WithReady

func WithReady(ready fnapi.Ready) ResourceModifier

WithReady sets the ready state of an fnapi.Resource.

type TestFunctionOpt

type TestFunctionOpt func(tc *FunctionTest)

func ExpectDesiredCompositeJSON

func ExpectDesiredCompositeJSON(rawJSON []byte, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredCompositeJSON is the same as ExpectDesiredCompositeObject but reads the object from a JSON document.

func ExpectDesiredCompositeObject

func ExpectDesiredCompositeObject(o runtime.Object, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredCompositeObject expects the given runtime.Object as desired composite as result of the function.

func ExpectDesiredCompositeYAML

func ExpectDesiredCompositeYAML(rawYAML []byte, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredCompositeYAML is the same as ExpectDesiredCompositeObject but reads the object from a single YAML document.

func ExpectDesiredResourceJSON

func ExpectDesiredResourceJSON(name string, rawJSON []byte, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredResourceJSON is the same as ExpectDesiredResourceObject but reads the object from a JSON document.

func ExpectDesiredResourceObject

func ExpectDesiredResourceObject(name string, o runtime.Object, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredResourceObject adds an object to the expected outcome of a function.

func ExpectDesiredResourceYAML

func ExpectDesiredResourceYAML(name string, rawYAML []byte, mods ...ResourceModifier) TestFunctionOpt

ExpectDesiredResourceYAML is the same as ExpectDesiredResourceObject but reads the object from a single YAML document.

func ExpectDesiredResourcesYAML

func ExpectDesiredResourcesYAML(rawYAML []byte) TestFunctionOpt

ExpectedDesiredResourcesYAML reads all objects from a multi-document YAML and expected them as desired resources from the function.

It uses the annotation AnnotationKeyResourceName to determine the name of the resource.

func ExpectError

func ExpectError(err error) TestFunctionOpt

ExpectError expects an error from a TestFunctionOpt.

func ExpectResults

func ExpectResults(results []*fnapi.Result) TestFunctionOpt

ExpectResults expects a list of fnapi.Result from a function.

func WithContextValue

func WithContextValue(key string, value any) TestFunctionOpt

WithContextValue sets the expected context field to value.

func WithContextValueJSON

func WithContextValueJSON(key string, rawJSON []byte) TestFunctionOpt

WithContextValueYAML reads a value from a JSON document and sets it as value of the given context field.

func WithContextValueYAML

func WithContextValueYAML(key string, rawYAML []byte) TestFunctionOpt

WithContextValueYAML reads a value from a single YAML document and sets it as value of the given context field.

func WithEnvironmentFromConfigsYAML

func WithEnvironmentFromConfigsYAML(rawYAML []byte) TestFunctionOpt

WithEnvironmentFromConfigsYAML is a custom test opt that creates an environment from a series of EnvironmentConfigs that are read from a multi-document YAML file and adds it as environment to the request context of a function.

Experimental: Environments are a Crossplane alpha feature and are prone to change in the future. This applies to this functions as well.

func WithInput

func WithInput(input any) TestFunctionOpt

WithInput sets the input that is passed to the function run. It accepts any value that can be marshaled to JSON.

func WithInputJSON

func WithInputJSON(inputJson []byte) TestFunctionOpt

WithInputJSON is the same as WithInput but accepts raw JSON.

func WithInputYAML

func WithInputYAML(inputYaml []byte) TestFunctionOpt

WithInputYAML is the same as WithInput but accepts raw YAML.

func WithObservedCompositeJSON

func WithObservedCompositeJSON(rawJSON []byte) TestFunctionOpt

WithObservedCompositeJSON reads an object from a JSON document and passes it as observed composite to the function.

func WithObservedCompositeObject

func WithObservedCompositeObject(o runtime.Object) TestFunctionOpt

WithObservedCompositeObject sets the observed composite to the given object.

func WithObservedCompositeYAML

func WithObservedCompositeYAML(rawYAML []byte) TestFunctionOpt

WithObservedCompositeYAML reads an object from a single YAML document and passes it as observed composite to the function.

func WithObservedResourceJSON

func WithObservedResourceJSON(name string, rawJSON []byte) TestFunctionOpt

WithObservedResourceJSON reads an object from a single JSON document and adds it to the observed state passed to the function.

func WithObservedResourceObject

func WithObservedResourceObject(name string, o runtime.Object) TestFunctionOpt

WithObservedResourceObject adds o to the observed state passed to the function.

func WithObservedResourceYAML

func WithObservedResourceYAML(name string, rawYAML []byte) TestFunctionOpt

WithObservedResourceYAML reads an object from a single YAML document and adds it to the observed state passed to the function.

func WithObservedResourcesYAML

func WithObservedResourcesYAML(rawYAML []byte) TestFunctionOpt

WithObservedResourcesYAML reads all objects from a multi-document YAML and passes them with the observed state to the function.

It uses the annotation AnnotationKeyResourceName to determine the name of the resource.

Jump to

Keyboard shortcuts

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