validation

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrUnrecognizedRuleType error = errors.New("Unrecognized Rule type")
	ErrDuplicateRuleName    error = errors.New("Duplicate Rule Name")
	ErrMissingRequiredKey   error = errors.New("Missing required key")
)
View Source
var (
	ErrInvalidJSONPath  error = fmt.Errorf("Invalid JSONPath")
	ErrMismatchingTypes error = fmt.Errorf("Mismatching type(s)")
	ErrWrongTypes       error = fmt.Errorf("Wrong type(s)")
)

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 *k6tv1.VirtualMachine) error

func (*Range) Includes

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

func (*Range) ToString

func (r *Range) ToString(v int64) string

can't be a Stringer

type Report

type Report struct {
	Ref           *Rule
	Satisfied     bool   // applied rule, with this result
	Message       string // if not satisfied, explain the reason
	IllegalReason error  // rule not applied, because of this error
}

type Result

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

func (*Result) SetRuleError

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

func (*Result) SetRuleStatus

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

func (*Result) Succeeded

func (r *Result) Succeeded() bool

func (*Result) ToStatusCauses

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

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`
	// 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 *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 *k6tv1.VirtualMachine) (bool, error)
	String() string
}

func NewEnumRule

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

func NewIntRule

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

func NewRegexRule

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

func NewStringRule

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

Jump to

Keyboard shortcuts

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