testing

package
v1.35.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: Apache-2.0 Imports: 61 Imported by: 17

Documentation

Overview

Package testing contains - all generic API tests which depend on Kubernetes API types - all cross-Kubernetes-API tests.

Index

Constants

This section is empty.

Variables

FuzzerFuncs is a list of fuzzer functions

Functions

func TestSelectableFieldLabelConversionsOfKind added in v1.2.0

func TestSelectableFieldLabelConversionsOfKind(t *testing.T, apiVersion string, kind string, fields fields.Set, labelMap map[string]string)

TestSelectableFieldLabelConversionsOfKind verifies that given resource have field label conversion defined for each its selectable field. fields contains selectable fields of the resource. labelMap maps deprecated labels to their canonical names.

func VerifyUpdateValidationEquivalence added in v1.35.0

func VerifyUpdateValidationEquivalence(t *testing.T, ctx context.Context, obj, old runtime.Object, validateUpdateFn ValidateUpdateFunc, expectedErrs field.ErrorList, testConfigs ...ValidationTestConfig)

VerifyUpdateValidationEquivalence provides a helper for testing the migration from hand-written imperative validation to declarative validation for update operations. It ensures that the validation logic remains consistent before and after the feature is enabled.

The function operates by running the provided validation function under two scenarios:

  1. With DeclarativeValidation and DeclarativeValidationTakeover feature gates disabled, simulating the legacy hand-written validation.
  2. With both feature gates enabled, using the new declarative validation rules.

It then asserts that the validation errors produced in both scenarios are equivalent, guaranteeing a safe migration. It also checks the errors against an expected set. It compares errors by field, origin and type; all three should match to be called equivalent. It also make sure all versions of the given API returns equivalent errors.

func VerifyValidationEquivalence added in v1.35.0

func VerifyValidationEquivalence(t *testing.T, ctx context.Context, obj runtime.Object, validateFn ValidateFunc, expectedErrs field.ErrorList, testConfigs ...ValidationTestConfig)

VerifyValidationEquivalence provides a helper for testing the migration from hand-written imperative validation to declarative validation. It ensures that the validation logic remains consistent before and after the feature is enabled.

The function operates by running the provided validation function under two scenarios:

  1. With DeclarativeValidation and DeclarativeValidationTakeover feature gates disabled, simulating the legacy hand-written validation.
  2. With both feature gates enabled, using the new declarative validation rules.

It then asserts that the validation errors produced in both scenarios are equivalent, guaranteeing a safe migration. It also checks the errors against an expected set. It compares errors by field, origin and type; all three should match to be called equivalent. It also make sure all versions of the given API returns equivalent errors.

func VerifyVersionedValidationEquivalence added in v1.33.0

func VerifyVersionedValidationEquivalence(t *testing.T, obj, old runtime.Object, testConfigs ...ValidationTestConfig)

VerifyVersionedValidationEquivalence tests that all versions of an API return equivalent validation errors. It accepts optional configuration to handle path normalization across API versions where structures differ.

Types

type ValidateFunc added in v1.35.0

type ValidateFunc func(ctx context.Context, obj runtime.Object) field.ErrorList

ValidateFunc is a function that runs validation.

type ValidateUpdateFunc added in v1.35.0

type ValidateUpdateFunc func(ctx context.Context, obj, old runtime.Object) field.ErrorList

ValidateUpdateFunc is a function that runs update validation.

type ValidationTestConfig added in v1.35.0

type ValidationTestConfig func(*validationOption)

func WithNormalizationRules added in v1.35.0

func WithNormalizationRules(rules ...field.NormalizationRule) ValidationTestConfig

func WithSubResources added in v1.35.0

func WithSubResources(subResources ...string) ValidationTestConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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