Documentation ¶
Index ¶
- Constants
- Variables
- func AssertValues(t *testing.T, expected, actual interface{}, arguments ...interface{}) bool
- func AssertValuesWithContext(context *Context, t *testing.T, expected, actual interface{}, ...) bool
- func FormatMessage(failure *Failure) string
- func NewDefaultMacroEvaluator() *toolbox.MacroEvaluator
- type AssertPath
- type Context
- type DataPath
- type Directive
- func (d *Directive) Add(target map[string]interface{})
- func (d *Directive) AddDataType(key, value string)
- func (d *Directive) AddElapsedRange(key, value string)
- func (d *Directive) AddKeyDoesNotExist(key string)
- func (d *Directive) AddKeyExists(key string)
- func (d *Directive) AddSort(key string)
- func (d *Directive) AddTimeLayout(key, value string)
- func (d *Directive) Apply(aMap map[string]interface{}) error
- func (d *Directive) ApplyKeyCaseInsensitive()
- func (d *Directive) DefaultTimeLayout() string
- func (d *Directive) ExtractDataTypes(aMap map[string]interface{})
- func (d *Directive) ExtractDirectives(aMap map[string]interface{}) bool
- func (d *Directive) IsDirectiveKey(key string) bool
- func (d *Directive) IsDirectiveValue(value string) bool
- type Directives
- type Failure
- type TestDirective
- func (r TestDirective) Cast(field, dataType string) TestDirective
- func (r TestDirective) IndexBy(key string) TestDirective
- func (r TestDirective) KeyCaseSensitive() TestDirective
- func (r TestDirective) SortText() TestDirective
- func (r TestDirective) TimeFormat(key, format string) TestDirective
- func (r TestDirective) TimeLayout(key, format string) TestDirective
- type Validation
Constants ¶
const ( KeyExistsDirective = "@exists@" KeyDoesNotExistsDirective = "@!exists@" TimeFormatDirective = "@timeFormat@" TimeLayoutDirective = "@timeLayout@" SwitchByDirective = "@switchCaseBy@" CastDataTypeDirective = "@cast@" IndexByDirective = "@indexBy@" KeyCaseSensitiveDirective = "@keyCaseSensitive@" CaseSensitiveDirective = "@caseSensitive@" SourceDirective = "@source@" SortTextDirective = "@sortText@" NumericPrecisionPointDirective = "@numericPrecisionPoint@" CoalesceWithZeroDirective = "@coalesceWithZero@" AssertPathDirective = "@assertPath@" LengthDirective = "@length@" StrictMapCheckDirective = "@strictMapCheck@" ElapsedRangeDirective = "@elapsedRange@" )
const ( MissingEntryViolation = "entry was missing" MissingItemViolation = "item was missing" ItemMismatchViolation = "item was mismatched" IncompatibleDataTypeViolation = "data type was incompatible" KeyExistsViolation = "key should exist" KeyDoesNotExistViolation = "key should not exist" EqualViolation = "value should be equal" NotEqualViolation = "value should not be equal" LengthViolation = "should have the same length" MissingCaseViolation = "missing switch/case value" RegExprMatchesViolation = "should match regexpr" RegExprDoesNotMatchViolation = "should not match regexpr" RangeViolation = "should be in range" RangeNotViolation = "should not be in range" ContainsViolation = "should contain fragment" DoesNotContainViolation = "should not contain fragment" PredicateViolation = "should pass predicate" ValueWasNil = "should have not nil" ElapseRangeViolation = "should elapsed be within" )
Variables ¶
var ValueProviderRegistry = toolbox.NewValueProviderRegistry()
ValueProviderRegistry represents value provider ValueProviderRegistry
Functions ¶
func AssertValues ¶
AssertValues validates expected against actual data structure
func AssertValuesWithContext ¶
func AssertValuesWithContext(context *Context, t *testing.T, expected, actual interface{}, arguments ...interface{}) bool
AssertValuesWithContext validates expected against actual data structure with context
func FormatMessage ¶
func NewDefaultMacroEvaluator ¶
func NewDefaultMacroEvaluator() *toolbox.MacroEvaluator
Types ¶
type AssertPath ¶ added in v0.3.0
type AssertPath struct { SubPath string Expected interface{} }
type Context ¶
type Context struct { toolbox.Context Directives *Directives Evaluator *toolbox.MacroEvaluator StrictDatTypeCheck bool }
Context represent validation context
func NewContext ¶
func NewContext(ctx toolbox.Context, directives *Directives, evaluator *toolbox.MacroEvaluator) *Context
NewContext returns a context
func NewDefaultContext ¶
func NewDefaultContext() *Context
NewDefaultContext returns default context
type DataPath ¶
type DataPath interface { //MatchingPath returns matching path MatchingPath() string //Path data path Path() string //Index creates subpath for supplied index Index(index int) DataPath //Index creates subpath for supplied key Key(key string) DataPath //Set source for this path, source may represent detail location of data point SetSource(string) //Get source from this path Source() string //Match returns a matched directive for this path Match(context *Context) *Directive //Match returns a directive for this path Directive() *Directive //Each traverse each data path node upto parent Each(callback func(path DataPath) bool) }
DataPath represents a dat path
type Directive ¶
type Directive struct { DataPath KeyExists map[string]bool KeyDoesNotExist map[string]bool TimeLayout string KeyCaseSensitive bool CaseSensitive bool StrictMapCheck bool TimeLayouts map[string]string DataType map[string]string ElaspedRange map[string]string Lengths map[string]int SwitchBy []string CoalesceWithZero bool NumericPrecisionPoint *int IndexBy []string Source string SortText bool AssertPaths []*AssertPath }
Match represents a validation TestDirective
func NewDirective ¶
NewDirective creates a new TestDirective for supplied path
func (*Directive) AddDataType ¶
AddDataType adds data type TestDirective
func (*Directive) AddElapsedRange ¶ added in v0.9.1
AddElapsedRange adds time layout TestDirective
func (*Directive) AddKeyDoesNotExist ¶
AddKeyDoesNotExist adds key does exist TestDirective
func (*Directive) AddKeyExists ¶
AddKeyExists adds key exists TestDirective
func (*Directive) AddTimeLayout ¶
AddTimeLayout adds time layout TestDirective
func (*Directive) ApplyKeyCaseInsensitive ¶ added in v0.2.2
func (d *Directive) ApplyKeyCaseInsensitive()
func (*Directive) DefaultTimeLayout ¶
DefaultTimeLayout returns default time layout
func (*Directive) ExtractDataTypes ¶
ExtractDataTypes extracts data from from supplied map
func (*Directive) ExtractDirectives ¶
ExtractDirective extract TestDirective from supplied map
func (*Directive) IsDirectiveKey ¶
IsDirectiveKey returns true if key is TestDirective
func (*Directive) IsDirectiveValue ¶
IsDirectiveKey returns true if value is TestDirective
type Directives ¶
Directives represent a directive
func NewDirectives ¶
func NewDirectives(directives ...*Directive) *Directives
NewDirectives returns new directives
func (*Directives) Match ¶
func (d *Directives) Match(path DataPath) *Directive
type Failure ¶
type Failure struct { Source string Path string Expected interface{} Actual interface{} Args []interface{} Reason string Message string }
Failure represents a validation failre
func NewFailure ¶
func NewFailure(source, path string, reason string, expected, actual interface{}, args ...interface{}) *Failure
NewFailure creates a new failure
type TestDirective ¶
type TestDirective map[string]interface{}
TestDirective represents TestDirective record
func IndexBy ¶
func IndexBy(key string) TestDirective
func TimeFormat ¶
func TimeFormat(key, format string) TestDirective
func TimeLayout ¶
func TimeLayout(key, format string) TestDirective
func (TestDirective) Cast ¶
func (r TestDirective) Cast(field, dataType string) TestDirective
func (TestDirective) IndexBy ¶
func (r TestDirective) IndexBy(key string) TestDirective
func (TestDirective) KeyCaseSensitive ¶ added in v0.2.2
func (r TestDirective) KeyCaseSensitive() TestDirective
func (TestDirective) SortText ¶
func (r TestDirective) SortText() TestDirective
func (TestDirective) TimeFormat ¶
func (r TestDirective) TimeFormat(key, format string) TestDirective
func (TestDirective) TimeLayout ¶
func (r TestDirective) TimeLayout(key, format string) TestDirective
type Validation ¶
type Validation struct { TagID string Description string PassedCount int FailedCount int Failures []*Failure }
Validation validation
func Assert ¶
func Assert(expected, actual interface{}, path DataPath) (*Validation, error)
Assert validates expected against actual data structure for supplied path
func AssertWithContext ¶
func AssertWithContext(expected, actual interface{}, path DataPath, context *Context) (*Validation, error)
AssertWithContext validates expected against actual data structure for supplied path and context
func (*Validation) AddFailure ¶
func (v *Validation) AddFailure(failure *Failure)
AddFailure add failure to current violation
func (*Validation) HasFailure ¶
func (v *Validation) HasFailure() bool
HasFailure returns true if validation has failures
func (*Validation) MergeFrom ¶
func (v *Validation) MergeFrom(source *Validation)
MergeFrom merges failures and passes from source