validation

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONPathPrefix string = "jsonpath::"
)

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 (
	ErrInvalidJSONPath = fmt.Errorf("invalid JSONPath")
)
View Source
var ErrNoValuesFound = errors.New("no values were found")

Functions

func NewJSONPathFromString

func NewJSONPathFromString(path string) (string, error)

func TrimJSONPath

func TrimJSONPath(path string) string

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 Path

type Path struct {
	// contains filtered or unexported fields
}

func NewPath

func NewPath(expr string) (*Path, error)

func (*Path) AsInt64

func (p *Path) AsInt64() ([]int64, error)

func (*Path) AsString

func (p *Path) AsString() ([]string, error)

func (*Path) Find

func (p *Path) Find(vm *k6tv1.VirtualMachine) error

func (*Path) Len

func (p *Path) Len() int

type Range

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

func (*Range) Decode

func (r *Range) Decode(Min, Max interface{}, 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    string `json:"rule"`
	Name    string `json:"name"`
	Path    string `json:"path"`
	Message string `json:"message"`
	// optional keys
	Valid       string `json:"valid,omitempty"`
	JustWarning bool   `json:"justWarning,omitempty"`
	// arguments (optional keys)
	Values    []string    `json:"values,omitempty"`
	Min       interface{} `json:"min,omitempty"`
	Max       interface{} `json:"max,omitempty"`
	MinLength interface{} `json:"minLength,omitempty"`
	MaxLength interface{} `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, error)

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)

Jump to

Keyboard shortcuts

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