Documentation
¶
Index ¶
- Variables
- func JSONFormatError(format string, err error) error
- func JSONFormatNotEqual(path string, exp string) error
- func JSONPathConversionError(path string, exp interface{}, got interface{}) error
- func JSONPathInvalid(path string, err error, node *yaml.Node) error
- func JSONPathInvalidNoRoot(path string, node *yaml.Node) error
- func JSONPathNotEqual(path string, exp interface{}, got interface{}) error
- func JSONPathNotFound(path string, err error) error
- func JSONSchemaFileNotFound(path string, node *yaml.Node) error
- func JSONSchemaInvalid(path string, err error) error
- func JSONSchemaValidateError(path string, err error) error
- func JSONUnmarshalError(err error, node *yaml.Node) error
- func New(exp *Expect, content []byte) api.Assertions
- func UnsupportedJSONSchemaReference(url string, node *yaml.Node) error
- type Expect
Constants ¶
This section is empty.
Variables ¶
var ( // ErrJSONPathInvalid returns an ErrParse when a JSONPath expression could // not be parsed. ErrJSONPathInvalid = fmt.Errorf( "%w: JSONPath invalid", api.ErrParse, ) // ErrJSONPathInvalidNoRoot returns an ErrParse when a JSONPath expression // does not start with '$' ErrJSONPathInvalidNoRoot = fmt.Errorf( "%w: expression must start with '$'", ErrJSONPathInvalid, ) // ErrJSONUnmarshalError is returned when JSON content cannot be decoded ErrJSONUnmarshalError = fmt.Errorf( "%w: failed to unmarshal JSON", api.ErrFailure, ) // ErrJSONPathNotFound returns an ErrFailure when a JSONPath expression // could not evaluate to a found element. ErrJSONPathNotFound = fmt.Errorf( "%w: failed to find element at JSONPath", api.ErrFailure, ) // ErrJSONPathConversionError returns an ErrFailure when a JSONPath // expression evaluated to a found element but could not be converted to a // string. ErrJSONPathConversionError = fmt.Errorf( "%w: JSONPath value could not be compared", api.ErrFailure, ) // ErrJSONPathNotEqual returns an ErrFailure when a JSONPath // expression evaluated to a found element but the value did not match an // expected string. ErrJSONPathNotEqual = fmt.Errorf( "%w: JSONPath values not equal", api.ErrFailure, ) // ErrJSONSchemaValidateError returns an ErrFailure when a JSONSchema could // not be parsed. ErrJSONSchemaValidateError = fmt.Errorf( "%w: failed to parse JSONSchema", api.ErrFailure, ) // ErrJSONSchemaInvalid returns an ErrFailure when some content could not // be validated with a JSONSchema. ErrJSONSchemaInvalid = fmt.Errorf( "%w: JSON content did not adhere to JSONSchema", api.ErrFailure, ) // ErrJSONFormatError returns an ErrFailure when a JSONFormat expression // could not evaluate to a found element. ErrJSONFormatError = fmt.Errorf( "%w: failed to determine JSON format", api.ErrFailure, ) // ErrJSONFormatNotEqual returns an ErrFailure when a an element at a // JSONPath was not in the expected format. ErrJSONFormatNotEqual = fmt.Errorf( "%w: JSON format not equal", api.ErrFailure, ) // ErrJSONSchemaFileNotFound indicates a specified JSONSchema file could // not be found. ErrJSONSchemaFileNotFound = fmt.Errorf( "%w: unable to find JSONSchema file", api.ErrParse, ) // ErrUnsupportedJSONSchemaReference indicates that a specified JSONSchema // file is referenced as an HTTP(S) URL instead of a file URI. ErrUnsupportedJSONSchemaReference = fmt.Errorf( "%w: unsupported JSONSchema reference", api.ErrParse, ) )
Functions ¶
func JSONFormatError ¶
JSONFormatError returns an ErrFailure when a JSONFormat expression could not evaluate to a found element.
func JSONFormatNotEqual ¶
JSONFormatNotEqual returns an ErrFailure when a an element at a JSONPath was not in the expected format.
func JSONPathConversionError ¶
JSONPathConversionError returns an ErrFailure when a JSONPath expression evaluated to a found element but the expected and found value types were incomparable.
func JSONPathInvalid ¶
JSONPathInvalid returns an ErrParse when a JSONPath expression could not be parsed.
func JSONPathInvalidNoRoot ¶
JSONPathInvalidNoRoot returns an ErrJSONPathInvalidNoRoot when a JSONPath expression does not start with '$'.
func JSONPathNotEqual ¶
JSONPathValueNotEqual returns an ErrFailure when a JSONPath expression evaluated to a found element but the value did not match an expected string.
func JSONPathNotFound ¶
JSONPathNotFound returns an ErrFailure when a JSONPath expression could not evaluate to a found element.
func JSONSchemaFileNotFound ¶
JSONSchemaFileNotFound returns ErrJSONSchemaFileNotFound for a supplied path.
func JSONSchemaInvalid ¶
JSONSchemaInvalid returns an ErrFailure when some content could not be validated with a JSONSchema.
func JSONSchemaValidateError ¶
JSONSchemaValidateError returns an ErrFailure when a JSONSchema could not be parsed.
func JSONUnmarshalError ¶
JSONUnmarshalError returns an ErrFailure when JSON content cannot be decoded.
func New ¶
func New( exp *Expect, content []byte, ) api.Assertions
New returns a `api.Assertions` that asserts various conditions about JSON content
func UnsupportedJSONSchemaReference ¶
UnsupportedJSONSchemaReference returns ErrUnsupportedJSONSchemaReference for a supplied URL.
Types ¶
type Expect ¶
type Expect struct { // Length of the expected JSON string. Len *int `yaml:"len,omitempty"` // Paths is a map, keyed by JSONPath expression, of expected values to find // at that expression. Paths map[string]string `yaml:"paths,omitempty"` // PathFormats is a map, keyed by JSONPath expression, of expected formats // that values found at the expression should have. PathFormats map[string]string `yaml:"path-formats,omitempty"` // Schema is a file path to the JSONSchema that the JSON should validate // against. Schema string `yaml:"schema,omitempty"` }
Expect represents one or more assertions about JSON data responses
func (*Expect) UnmarshalYAML ¶
UnmarshalYAML is a custom unmarshaler that ensures that JSONPath expressions contained in the Expect are valid.