Documentation ¶
Overview ¶
Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.
Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2024 Datadog, Inc.
This struct cannot be within the ddmark_test package in order to be properly loaded by the loader package, inherent to the markers
Index ¶
- Variables
- func CleanupAllLibraries() error
- func GetErrorList(errorList []error) string
- func Register(reg *k8smarkers.Registry) error
- type AtLeastOneOf
- type AtLeastOneOfTestStruct
- type Client
- type ClientMock
- func (_m *ClientMock) CleanupLibraries() error
- func (_m *ClientMock) EXPECT() *ClientMock_Expecter
- func (_m *ClientMock) ValidateStruct(marshalledStruct interface{}, filePath string) []error
- func (_m *ClientMock) ValidateStructMultierror(marshalledStruct interface{}, filePath string) *multierror.Error
- type ClientMock_CleanupLibraries_Call
- type ClientMock_Expecter
- func (_e *ClientMock_Expecter) CleanupLibraries() *ClientMock_CleanupLibraries_Call
- func (_e *ClientMock_Expecter) ValidateStruct(marshalledStruct interface{}, filePath interface{}) *ClientMock_ValidateStruct_Call
- func (_e *ClientMock_Expecter) ValidateStructMultierror(marshalledStruct interface{}, filePath interface{}) *ClientMock_ValidateStructMultierror_Call
- type ClientMock_ValidateStructMultierror_Call
- func (_c *ClientMock_ValidateStructMultierror_Call) Return(retErr *multierror.Error) *ClientMock_ValidateStructMultierror_Call
- func (_c *ClientMock_ValidateStructMultierror_Call) Run(run func(marshalledStruct interface{}, filePath string)) *ClientMock_ValidateStructMultierror_Call
- func (_c *ClientMock_ValidateStructMultierror_Call) RunAndReturn(run func(interface{}, string) *multierror.Error) *ClientMock_ValidateStructMultierror_Call
- type ClientMock_ValidateStruct_Call
- func (_c *ClientMock_ValidateStruct_Call) Return(_a0 []error) *ClientMock_ValidateStruct_Call
- func (_c *ClientMock_ValidateStruct_Call) Run(run func(marshalledStruct interface{}, filePath string)) *ClientMock_ValidateStruct_Call
- func (_c *ClientMock_ValidateStruct_Call) RunAndReturn(run func(interface{}, string) []error) *ClientMock_ValidateStruct_Call
- type DDValidationMarker
- type DDValidationMarkerMock
- type DDValidationMarkerMock_ApplyRule_Call
- func (_c *DDValidationMarkerMock_ApplyRule_Call) Return(_a0 error) *DDValidationMarkerMock_ApplyRule_Call
- func (_c *DDValidationMarkerMock_ApplyRule_Call) Run(run func(_a0 reflect.Value)) *DDValidationMarkerMock_ApplyRule_Call
- func (_c *DDValidationMarkerMock_ApplyRule_Call) RunAndReturn(run func(reflect.Value) error) *DDValidationMarkerMock_ApplyRule_Call
- type DDValidationMarkerMock_Expecter
- func (_e *DDValidationMarkerMock_Expecter) ApplyRule(_a0 interface{}) *DDValidationMarkerMock_ApplyRule_Call
- func (_e *DDValidationMarkerMock_Expecter) TypeCheckError(_a0 interface{}) *DDValidationMarkerMock_TypeCheckError_Call
- func (_e *DDValidationMarkerMock_Expecter) ValueCheckError() *DDValidationMarkerMock_ValueCheckError_Call
- type DDValidationMarkerMock_TypeCheckError_Call
- func (_c *DDValidationMarkerMock_TypeCheckError_Call) Return(_a0 error) *DDValidationMarkerMock_TypeCheckError_Call
- func (_c *DDValidationMarkerMock_TypeCheckError_Call) Run(run func(_a0 reflect.Value)) *DDValidationMarkerMock_TypeCheckError_Call
- func (_c *DDValidationMarkerMock_TypeCheckError_Call) RunAndReturn(run func(reflect.Value) error) *DDValidationMarkerMock_TypeCheckError_Call
- type DDValidationMarkerMock_ValueCheckError_Call
- func (_c *DDValidationMarkerMock_ValueCheckError_Call) Return(_a0 error) *DDValidationMarkerMock_ValueCheckError_Call
- func (_c *DDValidationMarkerMock_ValueCheckError_Call) Run(run func()) *DDValidationMarkerMock_ValueCheckError_Call
- func (_c *DDValidationMarkerMock_ValueCheckError_Call) RunAndReturn(run func() error) *DDValidationMarkerMock_ValueCheckError_Call
- type Enum
- type EnumTestStruct
- type ExclusiveFields
- type ExclusiveFieldsTestStruct
- type LinkedFieldsValue
- type LinkedFieldsValueTestStruct
- type LinkedFieldsValueWithTrigger
- type LinkedFieldsValueWithTriggerTestStruct
- type Maximum
- type MinMaxTestStruct
- type Minimum
- type Required
- type RequiredTestStruct
- type Teststruct
Constants ¶
This section is empty.
Variables ¶
var (
AllDefinitions []*k8smarkers.Definition
)
AllDefinitions contains all marker definitions for this package.
var EmbeddedDDMarkAPI embed.FS
EmbeddedDDMarkAPI includes the teststruct so it can be statically exported for ddmark testing
Functions ¶
func CleanupAllLibraries ¶
func CleanupAllLibraries() error
CleanupAllLibraries deletes the common ddmark lib folder ($GOPATH/src/ddmarktemp/*) Will remove the disk dependencies for all ddmark clients.
func GetErrorList ¶
GetErrorList returns a list of errors as a string
func Register ¶
func Register(reg *k8smarkers.Registry) error
Types ¶
type AtLeastOneOf ¶
type AtLeastOneOf []string
AtLeastOneOf can be applied to structs, and asserts at least one of the following fields is non-'nil'
func (AtLeastOneOf) TypeCheckError ¶
func (a AtLeastOneOf) TypeCheckError(fieldValue reflect.Value) error
func (AtLeastOneOf) ValueCheckError ¶
func (a AtLeastOneOf) ValueCheckError() error
type AtLeastOneOfTestStruct ¶
type AtLeastOneOfTestStruct struct { RandomIntField int // allows to actually check all-empty structs StrField string PStrField *string IntField int PIntField *int AIntField []int }
+ddmark:validation:AtLeastOneOf={StrField,IntField} +ddmark:validation:AtLeastOneOf={PStrField,PIntField,AIntField}
type Client ¶
type Client interface { // ValidateStruct applies struct markers found in structPkgs struct definitions to a marshalledStruct object. // It allows to enforce ddmark rules onto that object, according to the constraints defined in struct file. ValidateStruct(marshalledStruct interface{}, filePath string) []error // ValidateStructMultierror is the parent function of ValidateStruct. // It allows users to leverage the multierror package for error management. ValidateStructMultierror(marshalledStruct interface{}, filePath string) (retErr *multierror.Error) // CleanupLibraries removes the disk files related to the client. CleanupLibraries() error }
Client interface to manage validation of struct fields
Client is the expected way to use DDMark. Create a client with ddmark.NewClient(embed.FS). The client interfaces with local-disk copies of the given files. DDMark clients can be used simultaneously, as they manage independent/separate disk resources.
Client creates local files in the GOPATH. Make sure to use Client.CleanupLibraries (or ddmark.CleanupAllLibraries) to remove them.
type ClientMock ¶
ClientMock is an autogenerated mock type for the Client type
func NewClientMock ¶
func NewClientMock(t interface { mock.TestingT Cleanup(func()) }) *ClientMock
NewClientMock creates a new instance of ClientMock. 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 (*ClientMock) CleanupLibraries ¶
func (_m *ClientMock) CleanupLibraries() error
CleanupLibraries provides a mock function with given fields:
func (*ClientMock) EXPECT ¶
func (_m *ClientMock) EXPECT() *ClientMock_Expecter
func (*ClientMock) ValidateStruct ¶
func (_m *ClientMock) ValidateStruct(marshalledStruct interface{}, filePath string) []error
ValidateStruct provides a mock function with given fields: marshalledStruct, filePath
func (*ClientMock) ValidateStructMultierror ¶
func (_m *ClientMock) ValidateStructMultierror(marshalledStruct interface{}, filePath string) *multierror.Error
ValidateStructMultierror provides a mock function with given fields: marshalledStruct, filePath
type ClientMock_CleanupLibraries_Call ¶
ClientMock_CleanupLibraries_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CleanupLibraries'
func (*ClientMock_CleanupLibraries_Call) Return ¶
func (_c *ClientMock_CleanupLibraries_Call) Return(_a0 error) *ClientMock_CleanupLibraries_Call
func (*ClientMock_CleanupLibraries_Call) Run ¶
func (_c *ClientMock_CleanupLibraries_Call) Run(run func()) *ClientMock_CleanupLibraries_Call
func (*ClientMock_CleanupLibraries_Call) RunAndReturn ¶
func (_c *ClientMock_CleanupLibraries_Call) RunAndReturn(run func() error) *ClientMock_CleanupLibraries_Call
type ClientMock_Expecter ¶
type ClientMock_Expecter struct {
// contains filtered or unexported fields
}
func (*ClientMock_Expecter) CleanupLibraries ¶
func (_e *ClientMock_Expecter) CleanupLibraries() *ClientMock_CleanupLibraries_Call
CleanupLibraries is a helper method to define mock.On call
func (*ClientMock_Expecter) ValidateStruct ¶
func (_e *ClientMock_Expecter) ValidateStruct(marshalledStruct interface{}, filePath interface{}) *ClientMock_ValidateStruct_Call
ValidateStruct is a helper method to define mock.On call
- marshalledStruct interface{}
- filePath string
func (*ClientMock_Expecter) ValidateStructMultierror ¶
func (_e *ClientMock_Expecter) ValidateStructMultierror(marshalledStruct interface{}, filePath interface{}) *ClientMock_ValidateStructMultierror_Call
ValidateStructMultierror is a helper method to define mock.On call
- marshalledStruct interface{}
- filePath string
type ClientMock_ValidateStructMultierror_Call ¶
ClientMock_ValidateStructMultierror_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateStructMultierror'
func (*ClientMock_ValidateStructMultierror_Call) Return ¶
func (_c *ClientMock_ValidateStructMultierror_Call) Return(retErr *multierror.Error) *ClientMock_ValidateStructMultierror_Call
func (*ClientMock_ValidateStructMultierror_Call) Run ¶
func (_c *ClientMock_ValidateStructMultierror_Call) Run(run func(marshalledStruct interface{}, filePath string)) *ClientMock_ValidateStructMultierror_Call
func (*ClientMock_ValidateStructMultierror_Call) RunAndReturn ¶
func (_c *ClientMock_ValidateStructMultierror_Call) RunAndReturn(run func(interface{}, string) *multierror.Error) *ClientMock_ValidateStructMultierror_Call
type ClientMock_ValidateStruct_Call ¶
ClientMock_ValidateStruct_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValidateStruct'
func (*ClientMock_ValidateStruct_Call) Return ¶
func (_c *ClientMock_ValidateStruct_Call) Return(_a0 []error) *ClientMock_ValidateStruct_Call
func (*ClientMock_ValidateStruct_Call) Run ¶
func (_c *ClientMock_ValidateStruct_Call) Run(run func(marshalledStruct interface{}, filePath string)) *ClientMock_ValidateStruct_Call
func (*ClientMock_ValidateStruct_Call) RunAndReturn ¶
func (_c *ClientMock_ValidateStruct_Call) RunAndReturn(run func(interface{}, string) []error) *ClientMock_ValidateStruct_Call
type DDValidationMarker ¶
type DDValidationMarker interface { // ApplyRule asserts the marker's rule is checked and returns an error if it isn't (invalidating the config) ApplyRule(reflect.Value) error // ValueCheckError returns a marker's error message for an incorrect value/presence check ValueCheckError() error // TypeCheckError returns a marker's error message for an incorrect type check TypeCheckError(reflect.Value) error }
DDValidationMarker is the interface for Validation Markers, which apply rules to a given structure's field
type DDValidationMarkerMock ¶
DDValidationMarkerMock is an autogenerated mock type for the DDValidationMarker type
func NewDDValidationMarkerMock ¶
func NewDDValidationMarkerMock(t interface { mock.TestingT Cleanup(func()) }) *DDValidationMarkerMock
NewDDValidationMarkerMock creates a new instance of DDValidationMarkerMock. 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 (*DDValidationMarkerMock) ApplyRule ¶
func (_m *DDValidationMarkerMock) ApplyRule(_a0 reflect.Value) error
ApplyRule provides a mock function with given fields: _a0
func (*DDValidationMarkerMock) EXPECT ¶
func (_m *DDValidationMarkerMock) EXPECT() *DDValidationMarkerMock_Expecter
func (*DDValidationMarkerMock) TypeCheckError ¶
func (_m *DDValidationMarkerMock) TypeCheckError(_a0 reflect.Value) error
TypeCheckError provides a mock function with given fields: _a0
func (*DDValidationMarkerMock) ValueCheckError ¶
func (_m *DDValidationMarkerMock) ValueCheckError() error
ValueCheckError provides a mock function with given fields:
type DDValidationMarkerMock_ApplyRule_Call ¶
DDValidationMarkerMock_ApplyRule_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ApplyRule'
func (*DDValidationMarkerMock_ApplyRule_Call) Return ¶
func (_c *DDValidationMarkerMock_ApplyRule_Call) Return(_a0 error) *DDValidationMarkerMock_ApplyRule_Call
func (*DDValidationMarkerMock_ApplyRule_Call) Run ¶
func (_c *DDValidationMarkerMock_ApplyRule_Call) Run(run func(_a0 reflect.Value)) *DDValidationMarkerMock_ApplyRule_Call
func (*DDValidationMarkerMock_ApplyRule_Call) RunAndReturn ¶
func (_c *DDValidationMarkerMock_ApplyRule_Call) RunAndReturn(run func(reflect.Value) error) *DDValidationMarkerMock_ApplyRule_Call
type DDValidationMarkerMock_Expecter ¶
type DDValidationMarkerMock_Expecter struct {
// contains filtered or unexported fields
}
func (*DDValidationMarkerMock_Expecter) ApplyRule ¶
func (_e *DDValidationMarkerMock_Expecter) ApplyRule(_a0 interface{}) *DDValidationMarkerMock_ApplyRule_Call
ApplyRule is a helper method to define mock.On call
- _a0 reflect.Value
func (*DDValidationMarkerMock_Expecter) TypeCheckError ¶
func (_e *DDValidationMarkerMock_Expecter) TypeCheckError(_a0 interface{}) *DDValidationMarkerMock_TypeCheckError_Call
TypeCheckError is a helper method to define mock.On call
- _a0 reflect.Value
func (*DDValidationMarkerMock_Expecter) ValueCheckError ¶
func (_e *DDValidationMarkerMock_Expecter) ValueCheckError() *DDValidationMarkerMock_ValueCheckError_Call
ValueCheckError is a helper method to define mock.On call
type DDValidationMarkerMock_TypeCheckError_Call ¶
DDValidationMarkerMock_TypeCheckError_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'TypeCheckError'
func (*DDValidationMarkerMock_TypeCheckError_Call) Return ¶
func (_c *DDValidationMarkerMock_TypeCheckError_Call) Return(_a0 error) *DDValidationMarkerMock_TypeCheckError_Call
func (*DDValidationMarkerMock_TypeCheckError_Call) Run ¶
func (_c *DDValidationMarkerMock_TypeCheckError_Call) Run(run func(_a0 reflect.Value)) *DDValidationMarkerMock_TypeCheckError_Call
func (*DDValidationMarkerMock_TypeCheckError_Call) RunAndReturn ¶
func (_c *DDValidationMarkerMock_TypeCheckError_Call) RunAndReturn(run func(reflect.Value) error) *DDValidationMarkerMock_TypeCheckError_Call
type DDValidationMarkerMock_ValueCheckError_Call ¶
DDValidationMarkerMock_ValueCheckError_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ValueCheckError'
func (*DDValidationMarkerMock_ValueCheckError_Call) Return ¶
func (_c *DDValidationMarkerMock_ValueCheckError_Call) Return(_a0 error) *DDValidationMarkerMock_ValueCheckError_Call
func (*DDValidationMarkerMock_ValueCheckError_Call) Run ¶
func (_c *DDValidationMarkerMock_ValueCheckError_Call) Run(run func()) *DDValidationMarkerMock_ValueCheckError_Call
func (*DDValidationMarkerMock_ValueCheckError_Call) RunAndReturn ¶
func (_c *DDValidationMarkerMock_ValueCheckError_Call) RunAndReturn(run func() error) *DDValidationMarkerMock_ValueCheckError_Call
type Enum ¶
type Enum []interface{}
Enum can be applied to any interface field and provides a restricted amount of possible values for that field. Values within the marker strictly need to fit the given field interface. Usage is recommended to simple types.
func (Enum) ValueCheckError ¶
type EnumTestStruct ¶
type ExclusiveFields ¶
type ExclusiveFields []string
ExclusiveFields can be applied to structs, and asserts that the first field can only be non-'nil' iff all of the other fields are 'nil'
func (ExclusiveFields) ApplyRule ¶
func (e ExclusiveFields) ApplyRule(fieldvalue reflect.Value) error
func (ExclusiveFields) TypeCheckError ¶
func (e ExclusiveFields) TypeCheckError(fieldValue reflect.Value) error
func (ExclusiveFields) ValueCheckError ¶
func (e ExclusiveFields) ValueCheckError() error
type ExclusiveFieldsTestStruct ¶
type ExclusiveFieldsTestStruct struct { IntField int PIntField *int StrField string PStrField *string BField int CField int }
+ddmark:validation:ExclusiveFields={PIntField,PStrField} +ddmark:validation:ExclusiveFields={PIntField,BField,CField} +ddmark:validation:ExclusiveFields={IntField,StrField}
type LinkedFieldsValue ¶
type LinkedFieldsValue []string
LinkedFieldsValue can be applied to structs, and asserts the fields in the list are either all 'nil' or all non-'nil'
func (LinkedFieldsValue) ApplyRule ¶
func (l LinkedFieldsValue) ApplyRule(fieldvalue reflect.Value) error
func (LinkedFieldsValue) TypeCheckError ¶
func (l LinkedFieldsValue) TypeCheckError(fieldValue reflect.Value) error
func (LinkedFieldsValue) ValueCheckError ¶
func (l LinkedFieldsValue) ValueCheckError() error
type LinkedFieldsValueTestStruct ¶
type LinkedFieldsValueTestStruct struct { RandomIntField int // allows to actually check all-empty structs StrField string PStrField *string IntField int PIntField *int AIntField []int }
+ddmark:validation:LinkedFieldsValue={StrField=aaa,IntField} +ddmark:validation:LinkedFieldsValue={PStrField,PIntField,AIntField}
type LinkedFieldsValueWithTrigger ¶
type LinkedFieldsValueWithTrigger []string
LinkedFieldsValueWithTrigger can be applied to structs, and asserts the following: - if first field exists (or has the indicated value), all the following fields need to exist (or have the indicated value) - fields in question can be int or strings
func (LinkedFieldsValueWithTrigger) ApplyRule ¶
func (l LinkedFieldsValueWithTrigger) ApplyRule(fieldvalue reflect.Value) error
func (LinkedFieldsValueWithTrigger) TypeCheckError ¶
func (l LinkedFieldsValueWithTrigger) TypeCheckError(fieldValue reflect.Value) error
func (LinkedFieldsValueWithTrigger) ValueCheckError ¶
func (l LinkedFieldsValueWithTrigger) ValueCheckError() error
type LinkedFieldsValueWithTriggerTestStruct ¶
type LinkedFieldsValueWithTriggerTestStruct struct { RandomIntField int // allows to actually check all-empty structs StrField string PStrField *string IntField int PIntField *int AIntField []int }
+ddmark:validation:LinkedFieldsValueWithTrigger={StrField=aaa,IntField=2} +ddmark:validation:LinkedFieldsValueWithTrigger={PStrField=bbb,PIntField=12,AIntField}
type Maximum ¶
type Maximum int
Maximum can applied to an int field and provides a (non-strict) maximum value for that field
func (Maximum) ValueCheckError ¶
type MinMaxTestStruct ¶
type Minimum ¶
type Minimum int
Minimum can applied to an int field and provides a (non-strict) minimum value for that field
func (Minimum) ValueCheckError ¶
type Required ¶
type Required bool
Required can be applied to any field, and asserts this field will return an error if not provided
func (Required) ValueCheckError ¶
type RequiredTestStruct ¶
type RequiredTestStruct struct { // +ddmark:validation:Required=true IntField int // +ddmark:validation:Required=true PIntField *int // +ddmark:validation:Required=true StrField string // +ddmark:validation:Required=true PStrField *string // +ddmark:validation:Required=true StructField struct { A int } // +ddmark:validation:Required=true PStructField *struct { A int } }
type Teststruct ¶
type Teststruct struct { MinMaxTest MinMaxTestStruct RequiredTest RequiredTestStruct EnumTest EnumTestStruct ExclusiveFieldsTest ExclusiveFieldsTestStruct LinkedFieldsValueTest LinkedFieldsValueTestStruct LinkedFieldsValueWithTriggerTest LinkedFieldsValueWithTriggerTestStruct AtLeastOneOfTest AtLeastOneOfTestStruct }