funcs

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 51 Imported by: 0

Documentation

Overview

Package funcs contains convenience functions for working with e2e-framework environments and feature tests.

Index

Constants

View Source
const DefaultPollInterval = time.Millisecond * 500

DefaultPollInterval is the suggested poll interval for wait.For.

Variables

View Source
var NotFound = notFound{} //nolint:gochecknoglobals // We treat this as a constant.

NotFound is a special 'want' value that indicates the supplied path should not be found.

Functions

func AddCrossplaneTypesToScheme

func AddCrossplaneTypesToScheme() env.Func

AddCrossplaneTypesToScheme adds Crossplane's core custom resource's to the environment's scheme. This allows the environment's client to work with said types.

func AllOf

func AllOf(fns ...features.Func) features.Func

AllOf runs the supplied functions in order.

func ApplyClaim added in v1.15.0

func ApplyClaim(manager, dir, cm string, options ...decoder.DecodeOption) features.Func

ApplyClaim applies the claim stored in the given folder and file and stores it in the test context for later retrival if needed.

func ApplyHandler

func ApplyHandler(r *resources.Resources, manager string, osh ...onSuccessHandler) decoder.HandlerFunc

ApplyHandler is a decoder.Handler that uses server-side apply to apply the supplied object.

func ApplyResources

func ApplyResources(manager, dir, pattern string, options ...decoder.DecodeOption) features.Func

ApplyResources applies all manifests under the supplied directory that match the supplied glob pattern (e.g. *.yaml). It uses server-side apply - fields are managed by the supplied field manager. It fails the test if any supplied resource cannot be applied successfully.

func AsFeaturesFunc

func AsFeaturesFunc(fn env.Func) features.Func

AsFeaturesFunc converts an env.Func to a features.Func. If the env.Func returns an error the calling test is failed with t.Fatal(err).

func CRDInitialNamesAccepted

func CRDInitialNamesAccepted() xpv1.Condition

CRDInitialNamesAccepted is the status condition CRDs emit when they're established. Most of our Crossplane status conditions are defined elsewhere (e.g. in the xpv1 package), but this isn't so we define it here for convenience.

func ClaimUnderTestMustNotChangeWithin added in v1.15.0

func ClaimUnderTestMustNotChangeWithin(d time.Duration) features.Func

ClaimUnderTestMustNotChangeWithin asserts that the claim available in the test context does not change within the given time.

func ComposedResourcesHaveFieldValueWithin added in v1.15.0

func ComposedResourcesHaveFieldValueWithin(d time.Duration, dir, file, path string, want any, filter func(object k8s.Object) bool, options ...decoder.DecodeOption) features.Func

ComposedResourcesHaveFieldValueWithin fails a test if the composed resources created by the claim does not have the supplied value at the supplied path within the supplied duration.

func CompositeResourceHasFieldValueWithin added in v1.15.0

func CompositeResourceHasFieldValueWithin(d time.Duration, dir, claimFile, path string, want any, options ...decoder.DecodeOption) features.Func

CompositeResourceHasFieldValueWithin asserts that the XR referred to by the claim in the given file has the specified value at the specified path within the specified time.

func CompositeResourceMustMatchWithin added in v1.15.0

func CompositeResourceMustMatchWithin(d time.Duration, dir, claimFile string, match func(xr *composite.Unstructured) bool, options ...decoder.DecodeOption) features.Func

CompositeResourceMustMatchWithin assert that a composite referred by the given file must be matched by the given function within the given timeout.

func CompositeUnderTestMustNotChangeWithin added in v1.15.0

func CompositeUnderTestMustNotChangeWithin(d time.Duration) features.Func

CompositeUnderTestMustNotChangeWithin asserts that the claim available in the test context does not change within the given time.

func CreateKindClusterWithConfig

func CreateKindClusterWithConfig(clusterName, configFilePath string) env.Func

CreateKindClusterWithConfig create kind cluster of the given name according to configuration referred via configFilePath. The configuration is placed in test context afterward.

func DeleteResources

func DeleteResources(dir, pattern string, options ...decoder.DecodeOption) features.Func

DeleteResources deletes (from the environment) all resources defined by the manifests under the supplied directory that match the supplied glob pattern (e.g. *.yaml).

func DeletionBlockedByUsageWebhook added in v1.14.0

func DeletionBlockedByUsageWebhook(dir, pattern string, options ...decoder.DecodeOption) features.Func

DeletionBlockedByUsageWebhook attempts deleting all resources defined by the manifests under the supplied directory that match the supplied glob pattern (e.g. *.yaml) and verifies that they are blocked by the usage webhook.

func DeploymentBecomesAvailableWithin

func DeploymentBecomesAvailableWithin(d time.Duration, namespace, name string) features.Func

DeploymentBecomesAvailableWithin fails a test if the supplied Deployment is not Available within the supplied duration.

func EnvFuncs

func EnvFuncs(fns ...env.Func) env.Func

EnvFuncs runs the supplied functions in order, returning the first error.

func FilterByGK

func FilterByGK(gk schema.GroupKind) func(o k8s.Object) bool

FilterByGK returns a filter function that returns true if the supplied object is of the supplied GroupKind.

func HelmInstall

func HelmInstall(o ...helm.Option) env.Func

HelmInstall installs a Helm chart.

func HelmRepo

func HelmRepo(o ...helm.Option) env.Func

HelmRepo manages a Helm repo.

func HelmUninstall

func HelmUninstall(o ...helm.Option) env.Func

HelmUninstall uninstalls a Helm chart.

func HelmUpgrade

func HelmUpgrade(o ...helm.Option) env.Func

HelmUpgrade upgrades a Helm chart.

func InBackground added in v1.14.0

func InBackground(fn features.Func) features.Func

InBackground runs the supplied function in a goroutine.

func ListedResourcesDeletedWithin added in v1.14.0

func ListedResourcesDeletedWithin(d time.Duration, list k8s.ObjectList, listOptions ...resources.ListOption) features.Func

ListedResourcesDeletedWithin fails a test if the supplied list of resources is not deleted within the supplied duration.

func ListedResourcesModifiedWith added in v1.14.0

func ListedResourcesModifiedWith(list k8s.ObjectList, min int, modify func(object k8s.Object), listOptions ...resources.ListOption) features.Func

ListedResourcesModifiedWith modifies the supplied list of resources with the supplied function and fails a test if the supplied number of resources were not modified within the supplied duration.

func ListedResourcesValidatedWithin added in v1.14.0

func ListedResourcesValidatedWithin(d time.Duration, list k8s.ObjectList, min int, validate func(object k8s.Object) bool, listOptions ...resources.ListOption) features.Func

ListedResourcesValidatedWithin fails a test if the supplied list of resources does not have the supplied number of resources that pass the supplied validation function within the supplied duration.

func LogResources added in v1.14.0

func LogResources(list k8s.ObjectList, listOptions ...resources.ListOption) features.Func

LogResources polls the given kind of resources and logs creations, deletions and changed conditions.

func ReadyToTestWithin

func ReadyToTestWithin(d time.Duration, namespace string) features.Func

ReadyToTestWithin fails a test if Crossplane is not ready to test within the supplied duration. It's typically called in a feature's Setup function. Its purpose isn't to test that Crossplane installed successfully (we have a specific test for that). Instead its purpose is to make sure tests don't start before Crossplane has finished installing.

func RelatedObjects added in v1.14.0

func RelatedObjects(ctx context.Context, t *testing.T, config *rest.Config, objs ...client.Object) ([]client.Object, error)

RelatedObjects returns all objects related to the supplied object through ownership, i.e. the returned objects are transitively owned by obj, or resource reference.

func ResourceCreatedWithin

func ResourceCreatedWithin(d time.Duration, o k8s.Object) features.Func

ResourceCreatedWithin fails a test if the supplied resource is not found to exist within the supplied duration.

func ResourceDeletedWithin

func ResourceDeletedWithin(d time.Duration, o k8s.Object) features.Func

ResourceDeletedWithin fails a test if the supplied resource is not deleted within the supplied duration.

func ResourceHasFieldValueWithin

func ResourceHasFieldValueWithin(d time.Duration, o k8s.Object, path string, want any) features.Func

ResourceHasFieldValueWithin fails a test if the supplied resource does not have the supplied value at the supplied field path within the supplied duration. The supplied 'want' value must cmp.Equal the actual value.

func ResourcesCreatedWithin

func ResourcesCreatedWithin(d time.Duration, dir, pattern string, options ...decoder.DecodeOption) features.Func

ResourcesCreatedWithin fails a test if the supplied resources are not found to exist within the supplied duration.

func ResourcesDeletedAfterListedAreGone added in v1.14.0

func ResourcesDeletedAfterListedAreGone(d time.Duration, dir, pattern string, list k8s.ObjectList, listOptions ...resources.ListOption) features.Func

ResourcesDeletedAfterListedAreGone will ensure that the resources matching the supplied pattern under the supplied directory are deleted after the supplied list of resources are deleted.

func ResourcesDeletedWithin

func ResourcesDeletedWithin(d time.Duration, dir, pattern string, options ...decoder.DecodeOption) features.Func

ResourcesDeletedWithin fails a test if the supplied resources are not deleted within the supplied duration.

func ResourcesFailToApply

func ResourcesFailToApply(manager, dir, pattern string, options ...decoder.DecodeOption) features.Func

ResourcesFailToApply applies all manifests under the supplied directory that match the supplied glob pattern (e.g. *.yaml). It uses server-side apply - fields are managed by the supplied field manager. It fails the test if any supplied resource _can_ be applied successfully - use it to test that the API server should reject a resource.

func ResourcesHaveConditionWithin

func ResourcesHaveConditionWithin(d time.Duration, dir, pattern string, cds ...xpv1.Condition) features.Func

ResourcesHaveConditionWithin fails a test if the supplied resources do not have (i.e. become) the supplied conditions within the supplied duration. Comparison of conditions is modulo messages.

func ResourcesHaveFieldValueWithin

func ResourcesHaveFieldValueWithin(d time.Duration, dir, pattern, path string, want any, options ...decoder.DecodeOption) features.Func

ResourcesHaveFieldValueWithin fails a test if the supplied resources do not have the supplied value at the supplied field path within the supplied duration. The supplied 'want' value must cmp.Equal the actual value.

func ServiceIngressEndPoint

func ServiceIngressEndPoint(ctx context.Context, cfg *envconf.Config, clusterName, namespace, serviceName string) (string, error)

ServiceIngressEndPoint returns endpoint (addr:port) that can be used for accessing the service in the cluster with the given name.

func SetAnnotationMutateOption added in v1.14.0

func SetAnnotationMutateOption(key, value string) decoder.DecodeOption

SetAnnotationMutateOption returns a DecodeOption that sets the supplied annotation on the decoded object.

Types

This section is empty.

Jump to

Keyboard shortcuts

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