validation

package
v0.13.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnrecognizedRuleType = errors.New("unrecognized Rule type")
	ErrDuplicateRuleName    = errors.New("duplicate Rule Name")
	ErrMissingRequiredKey   = errors.New("missing required key")
	ErrUnsatisfiedRule      = errors.New("rule is not satisfied")
)
View Source
var ErrNoValuesFound = errors.New("no values were found")

Functions

This section is empty.

Types

type Evaluator

type Evaluator struct {
	Sink io.Writer
}

func NewEvaluator

func NewEvaluator() *Evaluator

func (*Evaluator) Evaluate

func (ev *Evaluator) Evaluate(rules []Rule, vm *k6tv1.VirtualMachine) *Result

Evaluate applies *all* the rules (greedy evaluation) to the given VM. Returns a Report for each applied Rule, but ordering isn't guaranteed. Use Report.Ref to crosslink Reports with Rules. The 'bool' return value is a syntetic result, it is true if Evaluation succeeded. The 'error' return value signals *internal* evaluation error. IOW 'false' evaluation *DOES NOT* imply error != nil

type Range

type Range struct {
	MinSet bool
	Min    int64
	MaxSet bool
	Max    int64
}

func (*Range) Decode

func (r *Range) Decode(min, max *path.IntOrPath, vm, ref *k6tv1.VirtualMachine) error

func (*Range) Includes

func (r *Range) Includes(v int64) bool

type Report

type Report struct {
	Ref       *Rule
	Skipped   bool   // because not valid, with `valid` defined as per spec
	Satisfied bool   // applied rule, with this result
	Message   string // human-friendly application output (debug/troubleshooting)
	Error     error  // *internal* error
}

type Result

type Result struct {
	Status []Report
	// contains filtered or unexported fields
}

func (*Result) Applied

func (r *Result) Applied(ru *Rule, satisfied bool, message string)

func (*Result) Fail

func (r *Result) Fail(ru *Rule, e error)

func (*Result) Skip

func (r *Result) Skip(ru *Rule)

func (*Result) Succeeded

func (r *Result) Succeeded() bool

func (*Result) ToStatusCauses

func (r *Result) ToStatusCauses() []metav1.StatusCause

func (*Result) Warn

func (r *Result) Warn(message string, e error)

Warn logs warnings into pod's log. Warnings are not included in result response.

type Rule

type Rule struct {
	// mandatory keys
	Rule    RuleType  `json:"rule"`
	Name    string    `json:"name"`
	Path    path.Path `json:"path"`
	Message string    `json:"message"`
	// optional keys
	Valid       *path.Path `json:"valid,omitempty"`
	JustWarning bool       `json:"justWarning,omitempty"`
	// arguments (optional keys)
	Values    []path.StringOrPath `json:"values,omitempty"`
	Min       *path.IntOrPath     `json:"min,omitempty"`
	Max       *path.IntOrPath     `json:"max,omitempty"`
	MinLength *path.IntOrPath     `json:"minLength,omitempty"`
	MaxLength *path.IntOrPath     `json:"maxLength,omitempty"`
	Regex     string              `json:"regex,omitempty"`
}

func ParseRules

func ParseRules(data []byte) ([]Rule, error)

func (*Rule) IsAppliableOn

func (r *Rule) IsAppliableOn(vm *k6tv1.VirtualMachine) bool

func (*Rule) Specialize

func (r *Rule) Specialize(vm, ref *k6tv1.VirtualMachine) (RuleApplier, error)

we need a vm reference to specialize a rule because few key fields may be JSONPath, and we need to walk them to get e.g. the value to check, or the limits to enforce.

type RuleApplier

type RuleApplier interface {
	Apply(vm, ref *k6tv1.VirtualMachine) (bool, error)
	String() string
}

func NewEnumRule

func NewEnumRule(r *Rule, vm, ref *k6tv1.VirtualMachine) (RuleApplier, error)

func NewIntRule

func NewIntRule(r *Rule, vm, ref *k6tv1.VirtualMachine) (RuleApplier, error)

func NewRegexRule

func NewRegexRule(r *Rule) (RuleApplier, error)

func NewStringRule

func NewStringRule(r *Rule, vm, ref *k6tv1.VirtualMachine) (RuleApplier, error)

type RuleType added in v0.13.0

type RuleType string
const (
	IntegerRule RuleType = "integer"
	StringRule  RuleType = "string"
	EnumRule    RuleType = "enum"
	RegexRule   RuleType = "regex"
)

func (RuleType) IsValid added in v0.13.0

func (r RuleType) IsValid() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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