matcher

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyID is used to identify elements by ID in an array
	KeyID = "_gst_id"
	// KeyIndex is used to identify elements by index in an array
	KeyIndex = "_gst_index"
)
View Source
const (
	NotExist = ValueType(iota)
	String
	Number
	Object
	Array
	Boolean
	Null
)

Variables

View Source
var (
	// JSONParserInstance is a singleton.
	JSONParserInstance = &JSONParser{}
)
View Source
var SuccessMatcherInstance = &SuccessMatcher{}

SuccessMatcherInstance is a singleton of SuccessMatcher.

Functions

func CreateNumberMatcher

func CreateNumberMatcher(input string) (types.GomegaMatcher, error)

CreateNumberMatcher returns a matcher for numbers. input must be a function.

func CreateStringMatcher

func CreateStringMatcher(input string) (types.GomegaMatcher, error)

CreateStringMatcher returns a matcher for string. input must be either a plain string or a function.

func IsBaseType

func IsBaseType(node Node) bool

IsBaseType returns true if node has base type.

func IsBaseTypes

func IsBaseTypes(nodes []Node) bool

IsObjects returns true if all elements in nodes has base type.

func IsObjects

func IsObjects(nodes []Node) bool

IsObjects returns true if all elements in nodes has type Object.

func MatchArrayWithArray

func MatchArrayWithArray(path string, exp, act []Node, parser Parser) (types.GomegaMatcher, bool, error)

MatchArrayWithArray matches act with exp as plain arrays.

func MatchArrayWithString

func MatchArrayWithString(path string, exp Node, act []Node) (types.GomegaMatcher, bool, error)

MatchArrayWithArray matches act with exp. exp must be a function.

func NewTimestampMatcher

func NewTimestampMatcher(expected time.Time, threshold time.Duration) types.GomegaMatcher

NewTimestampMatcher returns a matcher that checks datatype.Timestamp and `expected` is within `threshold`.

func ParseTime

func ParseTime(str string) (time.Time, error)

ParseTime parses str with format time.RFC3339Nano.

func Replace

func Replace(data []byte, vars map[string]string) ([]byte, error)

Replace returns data with all variables replaced with values in vars. If any variable is not defined in vars, an error is returned.

func Walk

func Walk(path string, exp, act Node, parser Parser) (types.GomegaMatcher, bool, error)

Walk recursively iterates the tree structure, matching elements in act with exp.

Types

type FailureMatcher

type FailureMatcher struct {
	Message string
}

FailureMatcher always fails. It is used to report custom error messages.

func NewFailureMatcher

func NewFailureMatcher(path, expected, actual string) *FailureMatcher

NewFailureMatcher returns a new *FailureMatcher.

func (*FailureMatcher) FailureMessage

func (matcher *FailureMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage implements types.GomegaMatcher.

func (*FailureMatcher) Match

func (matcher *FailureMatcher) Match(actual interface{}) (success bool, err error)

Match implements types.GomegaMatcher.

func (*FailureMatcher) NegatedFailureMessage

func (matcher *FailureMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage implements types.GomegaMatcher.

type JSONParser

type JSONParser struct {
}

JSONParser is parser for JSON.

func (*JSONParser) Delete

func (p *JSONParser) Delete(data []byte, key string) []byte

Delete implements Parser.

func (*JSONParser) GetArray

func (p *JSONParser) GetArray(data []byte) []Node

GetArray implements Parser.

func (*JSONParser) GetFields

func (p *JSONParser) GetFields(data []byte) map[string]Node

GetFields implements Parser.

func (*JSONParser) ValidateObject

func (p *JSONParser) ValidateObject(data []byte) error

ValidateObject implements Parser.

type Node

type Node struct {
	Type  ValueType
	Value []byte
}

Node represents an abstract node in tree structure.

func (Node) String

func (n Node) String() string

String returns string.

type Nodes

type Nodes []Node

Nodes represents []Node

func (Nodes) String

func (ns Nodes) String() string

String returns string.

type Parser

type Parser interface {
	ValidateObject(data []byte) error
	GetFields(data []byte) map[string]Node
	GetArray(data []byte) []Node
	Delete(data []byte, key string) []byte
}

Parser represents a parser for data types.

type SuccessMatcher

type SuccessMatcher struct {
}

SuccessMatcher always succeeds. It is used as a placeholder for success matches.

func (*SuccessMatcher) FailureMessage

func (matcher *SuccessMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage implements types.GomegaMatcher.

func (*SuccessMatcher) Match

func (matcher *SuccessMatcher) Match(actual interface{}) (success bool, err error)

Match implements types.GomegaMatcher.

func (*SuccessMatcher) NegatedFailureMessage

func (matcher *SuccessMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage implements types.GomegaMatcher.

type TimestampMatcher

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

TimestampMatcher matches timestamps.

func (*TimestampMatcher) FailureMessage

func (matcher *TimestampMatcher) FailureMessage(actual interface{}) string

FailureMessage returns failure message.

func (*TimestampMatcher) Match

func (matcher *TimestampMatcher) Match(actual interface{}) (bool, error)

Match matches a `string` formatted with RFC3339Nano.

func (*TimestampMatcher) NegatedFailureMessage

func (matcher *TimestampMatcher) NegatedFailureMessage(actual interface{}) string

NegatedFailureMessage returns negated failure message.

type ValueType

type ValueType int

ValueType defines value types available.

func (ValueType) String

func (t ValueType) String() string

String returns string.

Jump to

Keyboard shortcuts

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