Documentation
¶
Overview ¶
Package testutils provides common test utilities for validator tests to eliminate duplication.
Index ¶
- func AssertValidationResult[T any](t *testing.T, testCase ValidatorTestCase[T], ...)
- func RunNewValidatorConstructorTest[T any](t *testing.T, constructorFunc func() validator.Validator[T])
- func RunValidateTest[T any](t *testing.T, contractTestFunc func(*testing.T), ...)
- func RunValidatorTests[T any](t *testing.T, validatorInstance validator.Validator[T], ...)
- type MetadataTestCaseConfig
- type ValidatorTestCase
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertValidationResult ¶
func AssertValidationResult[T any]( t *testing.T, testCase ValidatorTestCase[T], result *validator.ValidationResult, )
AssertValidationResult provides a common assertion pattern for validation results.
func RunNewValidatorConstructorTest ¶
func RunNewValidatorConstructorTest[T any]( t *testing.T, constructorFunc func() validator.Validator[T], )
RunNewValidatorConstructorTest runs a common test pattern for validator constructors. This eliminates duplication of NewValidator constructor tests across validator test files.
func RunValidateTest ¶
func RunValidateTest[T any]( t *testing.T, contractTestFunc func(*testing.T), edgeTestFuncs ...func(*testing.T), )
RunValidateTest runs a common test pattern for the main Validate method. This eliminates duplication of TestValidate function structure across validator test files.
func RunValidatorTests ¶
func RunValidatorTests[T any]( t *testing.T, validatorInstance validator.Validator[T], testCases []ValidatorTestCase[T], assertFunc func(*testing.T, ValidatorTestCase[T], *validator.ValidationResult), )
RunValidatorTests runs a common test pattern for validator implementations. This eliminates duplication between different validator test files.
Types ¶
type MetadataTestCaseConfig ¶
MetadataTestCaseConfig contains configuration for metadata validation test cases.
type ValidatorTestCase ¶
type ValidatorTestCase[T any] struct { Name string Config T ExpectedValid bool ExpectedErrors []validator.ValidationError }
ValidatorTestCase represents a common test case structure for validator tests.
func CreateMetadataValidationTestCases ¶
func CreateMetadataValidationTestCases[T any]( configFactory func() T, setKind func(T, string), setAPIVersion func(T, string), config MetadataTestCaseConfig, ) []ValidatorTestCase[T]
CreateMetadataValidationTestCases creates common metadata validation test cases. This eliminates duplication of Kind and APIVersion validation tests across validators. The configFactory function should create a new instance each time it's called.
func CreateNilConfigTestCase ¶
func CreateNilConfigTestCase[T any]() ValidatorTestCase[T]
CreateNilConfigTestCase creates a standard test case for nil configuration validation. This only works correctly for pointer types where the zero value is nil.