Documentation
¶
Overview ¶
Package validator provides interfaces for configuration file validation.
Index ¶
- type FileLocation
- type MockValidator
- type MockValidator_Expecter
- type MockValidator_Validate_Call
- func (_c *MockValidator_Validate_Call[T]) Return(validationResult *ValidationResult) *MockValidator_Validate_Call[T]
- func (_c *MockValidator_Validate_Call[T]) Run(run func(config T)) *MockValidator_Validate_Call[T]
- func (_c *MockValidator_Validate_Call[T]) RunAndReturn(run func(config T) *ValidationResult) *MockValidator_Validate_Call[T]
- type ValidationError
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileLocation ¶
type FileLocation struct {
// FilePath is the absolute path to the configuration file
FilePath string `json:"filePath" yaml:"filePath"`
// Line is the line number where the error occurred (1-based)
Line int `json:"line" yaml:"line"`
// Column is the column number where the error occurred (1-based, optional)
Column int `json:"column" yaml:"column"`
}
FileLocation provides precise location information for validation errors.
func NewFileLocation ¶
func NewFileLocation(filePath string, line, column int) FileLocation
NewFileLocation creates a new FileLocation with the specified parameters.
func (FileLocation) String ¶
func (fl FileLocation) String() string
String returns a formatted string representation of the file location.
type MockValidator ¶
MockValidator is an autogenerated mock type for the Validator type
func NewMockValidator ¶
func NewMockValidator[T any](t interface { mock.TestingT Cleanup(func()) }) *MockValidator[T]
NewMockValidator creates a new instance of MockValidator. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockValidator[T]) EXPECT ¶
func (_m *MockValidator[T]) EXPECT() *MockValidator_Expecter[T]
func (*MockValidator[T]) Validate ¶
func (_mock *MockValidator[T]) Validate(config T) *ValidationResult
Validate provides a mock function for the type MockValidator
type MockValidator_Expecter ¶
type MockValidator_Expecter[T any] struct { // contains filtered or unexported fields }
func (*MockValidator_Expecter[T]) Validate ¶
func (_e *MockValidator_Expecter[T]) Validate(config interface{}) *MockValidator_Validate_Call[T]
Validate is a helper method to define mock.On call
- config T
type MockValidator_Validate_Call ¶
MockValidator_Validate_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Validate'
func (*MockValidator_Validate_Call[T]) Return ¶
func (_c *MockValidator_Validate_Call[T]) Return(validationResult *ValidationResult) *MockValidator_Validate_Call[T]
func (*MockValidator_Validate_Call[T]) Run ¶
func (_c *MockValidator_Validate_Call[T]) Run(run func(config T)) *MockValidator_Validate_Call[T]
func (*MockValidator_Validate_Call[T]) RunAndReturn ¶
func (_c *MockValidator_Validate_Call[T]) RunAndReturn(run func(config T) *ValidationResult) *MockValidator_Validate_Call[T]
type ValidationError ¶
type ValidationError struct {
// Field is the specific field path that failed validation (e.g., "spec.distribution", "metadata.name")
Field string `json:"field" yaml:"field"`
// Message is a human-readable description of the validation error
Message string `json:"message" yaml:"message"`
// CurrentValue is the actual value that was found in the configuration
CurrentValue any `json:"currentValue" yaml:"currentValue"`
// ExpectedValue is the expected value or constraint that was violated
ExpectedValue any `json:"expectedValue" yaml:"expectedValue"`
// FixSuggestion provides actionable guidance on how to fix the error
FixSuggestion string `json:"fixSuggestion" yaml:"fixSuggestion"`
// Location provides file and line information where the error occurred
Location FileLocation `json:"location" yaml:"location"`
}
ValidationError represents a specific validation failure with detailed context and actionable remediation.
func NewValidationError ¶
func NewValidationError( field, message string, currentValue, expectedValue any, fixSuggestion string, location FileLocation, ) ValidationError
NewValidationError creates a new ValidationError with the specified parameters.
func (ValidationError) Error ¶
func (ve ValidationError) Error() string
Error implements the error interface for ValidationError.
type ValidationResult ¶
type ValidationResult struct {
// Valid indicates overall validation status (true if no errors)
Valid bool `json:"valid" yaml:"valid"`
// Errors contains all validation errors found
Errors []ValidationError `json:"errors" yaml:"errors"`
// Warnings contains validation warnings (non-blocking)
Warnings []ValidationError `json:"warnings" yaml:"warnings"`
// ConfigFile is the path to the configuration file that was validated
ConfigFile string `json:"configFile" yaml:"configFile"`
}
ValidationResult contains the overall validation status and collection of validation errors.
func NewValidationResult ¶
func NewValidationResult(configFile string) *ValidationResult
NewValidationResult creates a new ValidationResult for the specified configuration file.
func (*ValidationResult) AddError ¶
func (vr *ValidationResult) AddError(err ValidationError)
AddError adds a validation error to the result and sets Valid to false.
func (*ValidationResult) AddWarning ¶
func (vr *ValidationResult) AddWarning(warning ValidationError)
AddWarning adds a validation warning to the result without affecting Valid status.
func (*ValidationResult) HasErrors ¶
func (vr *ValidationResult) HasErrors() bool
HasErrors returns true if the validation result contains any errors.
func (*ValidationResult) HasWarnings ¶
func (vr *ValidationResult) HasWarnings() bool
HasWarnings returns true if the validation result contains any warnings.
type Validator ¶
type Validator[T any] interface { // Validate performs validation on an already parsed configuration struct. // This method focuses on semantic validation of the configuration content. // // Parameters: // - config: Already parsed configuration struct of type T // // Returns: // - ValidationResult containing status and any errors found // // Contract Requirements: // - MUST validate semantic correctness of configuration // - MUST check field constraints and dependencies // - MUST return actionable error messages // - MUST be idempotent (same input = same output) // - MUST handle nil or malformed structs gracefully Validate(config T) *ValidationResult }
Validator defines the interface for configuration file validators. All implementations must be thread-safe and suitable for concurrent use. The type parameter T specifies the specific configuration type this validator handles.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package k3d provides K3d configuration validation functionality.
|
Package k3d provides K3d configuration validation functionality. |
|
Package kind provides Kind configuration validation functionality.
|
Package kind provides Kind configuration validation functionality. |
|
Package ksail provides validation for KSail cluster configurations.
|
Package ksail provides validation for KSail cluster configurations. |
|
Package metadata provides shared metadata validation utilities used across multiple validators.
|
Package metadata provides shared metadata validation utilities used across multiple validators. |
|
Package testutils provides common test utilities for validator tests to eliminate duplication.
|
Package testutils provides common test utilities for validator tests to eliminate duplication. |