assertjson

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package assertjson provides methods for testing JSON values. Selecting JSON values provided by JSON Pointer Syntax (https://tools.ietf.org/html/rfc6901).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileHas

func FileHas(t TestingT, filename string, jsonAssert JSONAssertFunc)

FileHas loads JSON from file and runs user callback for testing its nodes.

func Has

func Has(t TestingT, data []byte, jsonAssert JSONAssertFunc)

Has - loads JSON from byte slice and runs user callback for testing its nodes.

Types

type ArrayAssertion added in v0.4.0

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

ArrayAssertion is used to build a chain of assertions for the array node.

func (*ArrayAssertion) Length added in v0.4.0

func (a *ArrayAssertion) Length() int

Length returns array underlying array length.

func (*ArrayAssertion) WithLength added in v0.4.0

func (a *ArrayAssertion) WithLength(expected int, msgAndArgs ...interface{}) *ArrayAssertion

WithLength asserts that the JSON node is an array with length equal to the given value.

func (*ArrayAssertion) WithLengthGreaterThan added in v0.4.0

func (a *ArrayAssertion) WithLengthGreaterThan(expected int, msgAndArgs ...interface{}) *ArrayAssertion

WithLengthGreaterThan asserts that the JSON node is an array with length greater than the value.

func (*ArrayAssertion) WithLengthGreaterThanOrEqual added in v0.4.0

func (a *ArrayAssertion) WithLengthGreaterThanOrEqual(expected int, msgAndArgs ...interface{}) *ArrayAssertion

WithLengthGreaterThanOrEqual asserts that the JSON node is an array with length greater than or equal to the value.

func (*ArrayAssertion) WithLengthLessThan added in v0.4.0

func (a *ArrayAssertion) WithLengthLessThan(expected int, msgAndArgs ...interface{}) *ArrayAssertion

WithLengthLessThan asserts that the JSON node is an array with length less than the value.

func (*ArrayAssertion) WithLengthLessThanOrEqual added in v0.4.0

func (a *ArrayAssertion) WithLengthLessThanOrEqual(expected int, msgAndArgs ...interface{}) *ArrayAssertion

WithLengthLessThanOrEqual asserts that the JSON node is an array with length less than or equal to the value.

func (*ArrayAssertion) WithUniqueElements added in v0.4.0

func (a *ArrayAssertion) WithUniqueElements(msgAndArgs ...interface{}) *ArrayAssertion

WithUniqueElements asserts that the JSON node is an array with unique elements.

type AssertJSON

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

AssertJSON - main structure that holds parsed JSON.

func NewAssertJSON added in v0.8.0

func NewAssertJSON(t TestingT, message string, data interface{}) *AssertJSON

func (*AssertJSON) At added in v0.3.0

func (j *AssertJSON) At(path ...interface{}) *AssertJSON

At is used to test assertions on some node in a batch. It returns AssertJSON object on that node.

func (*AssertJSON) Atf added in v0.3.0

func (j *AssertJSON) Atf(format string, a ...interface{}) *AssertJSON

Atf is used to test assertions on some node in a batch. It returns AssertJSON object on that node. It calculates path by applying fmt.Sprintf function. Deprecated: use At() with multiple arguments.

func (*AssertJSON) Node

func (j *AssertJSON) Node(path ...interface{}) *AssertNode

Node searches for JSON node by JSON Path Syntax. Returns struct for asserting the node values.

func (*AssertJSON) Nodef added in v0.3.0

func (j *AssertJSON) Nodef(format string, a ...interface{}) *AssertNode

Nodef searches for JSON node by JSON Path Syntax. Returns struct for asserting the node values. It calculates path by applying fmt.Sprintf function. Deprecated: use Node() with multiple arguments.

type AssertNode

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

AssertNode - structure for asserting JSON node.

func (*AssertNode) ArrayLength added in v0.4.0

func (node *AssertNode) ArrayLength() int

ArrayLength asserts that JSON node is array and return its length. It is an alias for IsArray().Length().

func (*AssertNode) Assert added in v0.6.0

func (node *AssertNode) Assert(jsonAssert JSONAssertFunc)

Assert executes JSON assertion on the current node value. This is useful when creating reusable assertion using functions.

func (*AssertNode) AssertString added in v0.2.1

func (node *AssertNode) AssertString(assertFunc func(t testing.TB, value string))

AssertString asserts that the JSON node has a string value and it is satisfied by the user function assertFunc. Deprecated: use IsString().Assert() instead.

func (*AssertNode) Contains

func (node *AssertNode) Contains(contain string, msgAndArgs ...interface{})

Contains asserts that the JSON node has a string value that contains a string.

func (*AssertNode) DoesNotContain

func (node *AssertNode) DoesNotContain(contain string, msgAndArgs ...interface{})

DoesNotContain asserts that the JSON node has a string value that does not contain a string.

func (*AssertNode) DoesNotExist

func (node *AssertNode) DoesNotExist(msgAndArgs ...interface{})

DoesNotExist asserts that the JSON node does not exist.

func (*AssertNode) DoesNotMatch

func (node *AssertNode) DoesNotMatch(regexp interface{}, msgAndArgs ...interface{})

DoesNotMatch asserts that the JSON node has a string value that does not match the regular expression.

func (*AssertNode) EqualJSON added in v0.4.0

func (node *AssertNode) EqualJSON(expected string, msgAndArgs ...interface{})

EqualJSON asserts that node is equal to JSON string.

func (*AssertNode) EqualToTheFloat

func (node *AssertNode) EqualToTheFloat(expectedValue float64, msgAndArgs ...interface{})

EqualToTheFloat asserts that the JSON node has a float value equals to the given value. Deprecated: use IsNumber() instead.

func (*AssertNode) EqualToTheInteger

func (node *AssertNode) EqualToTheInteger(expectedValue int, msgAndArgs ...interface{})

EqualToTheInteger asserts that the JSON node has an integer value equals to the given value. Deprecated: use IsInteger() instead.

func (*AssertNode) EqualToTheString

func (node *AssertNode) EqualToTheString(expectedValue string, msgAndArgs ...interface{})

EqualToTheString asserts that the JSON node has a string value equals to the given value. Deprecated: use IsString().EqualTo() instead.

func (*AssertNode) Exists

func (node *AssertNode) Exists(msgAndArgs ...interface{}) bool

Exists asserts that the JSON node exists. Returns true if node exists.

func (*AssertNode) Float added in v0.4.0

func (node *AssertNode) Float() float64

Float returns the JSON node value as a 64-bit float. If node does not exist it returns a zero. If node value is not numeric, it logs the error and returns a zero value.

func (*AssertNode) ForEach added in v0.4.0

func (node *AssertNode) ForEach(assertNode func(node *AssertNode))

ForEach executes callback function for node assertion on each array or object node.

func (*AssertNode) Integer added in v0.4.0

func (node *AssertNode) Integer() int

Integer returns the JSON node value as an integer. If node does not exist it returns a zero. If node value is not an integer, it logs the error and returns a zero value.

func (*AssertNode) IsArray added in v0.4.0

func (node *AssertNode) IsArray(msgAndArgs ...interface{}) *ArrayAssertion

IsArray asserts that the JSON node is an array. It returns ArrayAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsArrayWithElementsCount

func (node *AssertNode) IsArrayWithElementsCount(count int, msgAndArgs ...interface{})

IsArrayWithElementsCount asserts that the JSON node is an array with given elements count. Deprecated: use IsArray().WithLength() instead.

func (*AssertNode) IsDate added in v0.5.0

func (node *AssertNode) IsDate(msgAndArgs ...interface{}) *TimeAssertion

IsDate asserts that the JSON node has a string value with date in "YYYY-MM-DD" format.

func (*AssertNode) IsEmail added in v0.4.0

func (node *AssertNode) IsEmail(msgAndArgs ...interface{})

IsEmail asserts that the JSON node has a string value with email. Validation is based on simplified pattern. It allows all values with an "@" symbol in, and a "." in the second host part of the email address.

func (*AssertNode) IsFalse

func (node *AssertNode) IsFalse(msgAndArgs ...interface{})

IsFalse asserts that the JSON node equals to the boolean with `false` value.

func (*AssertNode) IsFloat

func (node *AssertNode) IsFloat(msgAndArgs ...interface{}) *NumberAssertion

IsFloat asserts that the JSON node has a float value. It returns NumberAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsHTML5Email added in v0.4.0

func (node *AssertNode) IsHTML5Email(msgAndArgs ...interface{})

IsHTML5Email asserts that the JSON node has a string value with email. Validation is based on pattern for HTML5 (see https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).

func (*AssertNode) IsInteger

func (node *AssertNode) IsInteger(msgAndArgs ...interface{}) *IntegerAssertion

IsInteger asserts that the JSON node has an integer value. It returns IntegerAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsJWT added in v0.5.0

func (node *AssertNode) IsJWT(keyFunc jwt.Keyfunc, msgAndArgs ...interface{}) *JWTAssertion

IsJWT asserts that the JSON node has a string value with JWT.

func (*AssertNode) IsNotNull

func (node *AssertNode) IsNotNull(msgAndArgs ...interface{})

IsNotNull asserts that the JSON node not equals to `null` value.

func (*AssertNode) IsNull

func (node *AssertNode) IsNull(msgAndArgs ...interface{})

IsNull asserts that the JSON node equals to `null` value.

func (*AssertNode) IsNumber added in v0.4.0

func (node *AssertNode) IsNumber(msgAndArgs ...interface{}) *NumberAssertion

IsNumber asserts that the JSON node has a float value. It returns NumberAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsNumberGreaterThan

func (node *AssertNode) IsNumberGreaterThan(value float64, msgAndArgs ...interface{})

IsNumberGreaterThan asserts that the JSON node has a number greater than the given value. Deprecated: use IsNumber().GreaterThan() instead.

func (*AssertNode) IsNumberGreaterThanOrEqual

func (node *AssertNode) IsNumberGreaterThanOrEqual(value float64, msgAndArgs ...interface{})

IsNumberGreaterThanOrEqual asserts that the JSON node has a number greater than or equal to the given value. Deprecated: use IsNumber().GreaterThanOrEqual() instead.

func (*AssertNode) IsNumberInRange

func (node *AssertNode) IsNumberInRange(min, max float64, msgAndArgs ...interface{})

IsNumberInRange asserts that the JSON node has a number with value in the given range. Deprecated: use IsNumber().GreaterThanOrEqual().LessThanOrEqual() instead.

func (*AssertNode) IsNumberLessThan

func (node *AssertNode) IsNumberLessThan(value float64, msgAndArgs ...interface{})

IsNumberLessThan asserts that the JSON node has a number less than the given value. Deprecated: use IsNumber().LessThan() instead.

func (*AssertNode) IsNumberLessThanOrEqual

func (node *AssertNode) IsNumberLessThanOrEqual(value float64, msgAndArgs ...interface{})

IsNumberLessThanOrEqual asserts that the JSON node has a number less than or equal to the given value. Deprecated: use IsNumber().LessThanOrEqual() instead.

func (*AssertNode) IsObject added in v0.4.0

func (node *AssertNode) IsObject(msgAndArgs ...interface{}) *ObjectAssertion

IsObject asserts that the JSON node is an object. It returns ObjectAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsObjectWithPropertiesCount

func (node *AssertNode) IsObjectWithPropertiesCount(count int, msgAndArgs ...interface{})

IsObjectWithPropertiesCount asserts that the JSON node is an object with given properties count. Deprecated: use IsObject().WithPropertiesCount() instead.

func (*AssertNode) IsString

func (node *AssertNode) IsString(msgAndArgs ...interface{}) *StringAssertion

IsString asserts that the JSON node has a string value. It returns StringAssertion to execute a chain of assertions for the node value.

func (*AssertNode) IsStringWithLength

func (node *AssertNode) IsStringWithLength(length int, msgAndArgs ...interface{})

IsStringWithLength asserts that the JSON node has a string value with length equal to the given value. Deprecated: use IsString().WithLength() instead.

func (*AssertNode) IsStringWithLengthInRange

func (node *AssertNode) IsStringWithLengthInRange(min int, max int, msgAndArgs ...interface{})

IsStringWithLengthInRange asserts that the JSON node has a string value with length in a given range. Deprecated: use IsString().WithLengthGreaterThanOrEqual().WithLengthLessThanOrEqual() instead.

func (*AssertNode) IsTime added in v0.5.0

func (node *AssertNode) IsTime(msgAndArgs ...interface{}) *TimeAssertion

IsTime asserts that the JSON node has a string value with time in RFC3339 format.

func (*AssertNode) IsTimeWithLayout added in v0.5.0

func (node *AssertNode) IsTimeWithLayout(layout string, msgAndArgs ...interface{}) *TimeAssertion

IsTimeWithLayout asserts that the JSON node has a string value with time with the given layout.

func (*AssertNode) IsTrue

func (node *AssertNode) IsTrue(msgAndArgs ...interface{})

IsTrue asserts that the JSON node equals to the boolean with `true` value.

func (*AssertNode) IsURL added in v0.4.0

func (node *AssertNode) IsURL(msgAndArgs ...interface{}) *URLAssertion

IsURL asserts that the JSON node has a string value with URL.

func (*AssertNode) IsUUID added in v0.4.0

func (node *AssertNode) IsUUID(msgAndArgs ...interface{}) *UUIDAssertion

IsUUID asserts that the JSON node has a string value with UUID.

func (*AssertNode) JSON added in v0.4.0

func (node *AssertNode) JSON() []byte

JSON returns the JSON node value as a marshaled JSON.

func (*AssertNode) JWT added in v0.5.0

func (node *AssertNode) JWT(keyFunc jwt.Keyfunc) *jwt.Token

JWT asserts that the JSON node is JWT and returns decoded jwt.Token. If value is not a valid JWT, then it will return empty struct. It is an alias for IsJWT().Value().

func (*AssertNode) Matches

func (node *AssertNode) Matches(regexp interface{}, msgAndArgs ...interface{})

Matches asserts that the JSON node has a string value that matches the regular expression.

func (*AssertNode) ObjectPropertiesCount added in v0.4.0

func (node *AssertNode) ObjectPropertiesCount() int

ObjectPropertiesCount asserts that JSON node is an object and return its properties count. It is an alias for IsObject().PropertiesCount().

func (*AssertNode) Print added in v0.6.2

func (node *AssertNode) Print()

func (*AssertNode) String added in v0.4.0

func (node *AssertNode) String() string

String returns the JSON node value as a string. If node does not exist it returns an empty string. If the node value is an integer it returns a formatted integer. If the node value is a float it returns a formatted float. Otherwise, it logs the error and returns an empty string.

func (*AssertNode) Time added in v0.5.0

func (node *AssertNode) Time() time.Time

Time asserts that the JSON node is time.Time and returns its value. If string is not a valid time it returns empty time. It is an alias for IsTime().Value().

func (*AssertNode) TimeWithLayout added in v0.5.0

func (node *AssertNode) TimeWithLayout(layout string) time.Time

TimeWithLayout asserts that the JSON node is time.Time with specific layout and returns its value. If string is not a valid time it returns empty time. It is an alias for IsTimeWithLayout().Value().

func (*AssertNode) UUID added in v0.4.0

func (node *AssertNode) UUID() uuid.UUID

UUID asserts that the JSON node is UUID and returns its value. If value is not a valid UUID, then it will return nil UUID. It is an alias for IsUUID().Value().

func (*AssertNode) Value added in v0.4.0

func (node *AssertNode) Value() interface{}

Value returns JSON node value as an interface. If node does not exist it returns nil.

type IntegerAssertion added in v0.4.0

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

IntegerAssertion is used to build a chain of assertions for the integer node.

func (*IntegerAssertion) EqualTo added in v0.4.0

func (a *IntegerAssertion) EqualTo(expected int, msgAndArgs ...interface{}) *IntegerAssertion

EqualTo asserts that the JSON node has an integer value equals to the given value.

func (*IntegerAssertion) GreaterThan added in v0.4.0

func (a *IntegerAssertion) GreaterThan(expected int, msgAndArgs ...interface{}) *IntegerAssertion

GreaterThan asserts that the JSON node has an integer value greater than the given value.

func (*IntegerAssertion) GreaterThanOrEqual added in v0.4.0

func (a *IntegerAssertion) GreaterThanOrEqual(expected int, msgAndArgs ...interface{}) *IntegerAssertion

GreaterThanOrEqual asserts that the JSON node has an integer value greater than or equal to the given value.

func (*IntegerAssertion) IsNotZero added in v0.7.0

func (a *IntegerAssertion) IsNotZero(msgAndArgs ...interface{}) *IntegerAssertion

IsNotZero asserts that the JSON node has an integer value not equals to 0.

func (*IntegerAssertion) IsZero added in v0.7.0

func (a *IntegerAssertion) IsZero(msgAndArgs ...interface{}) *IntegerAssertion

IsZero asserts that the JSON node has an integer value equals to 0.

func (*IntegerAssertion) LessThan added in v0.4.0

func (a *IntegerAssertion) LessThan(expected int, msgAndArgs ...interface{}) *IntegerAssertion

LessThan asserts that the JSON node has an integer value less than the given value.

func (*IntegerAssertion) LessThanOrEqual added in v0.4.0

func (a *IntegerAssertion) LessThanOrEqual(expected int, msgAndArgs ...interface{}) *IntegerAssertion

LessThanOrEqual asserts that the JSON node has an integer value less than or equal to the given value.

func (*IntegerAssertion) NotEqualTo added in v0.4.2

func (a *IntegerAssertion) NotEqualTo(expected int, msgAndArgs ...interface{}) *IntegerAssertion

NotEqualTo asserts that the JSON node has an integer value not equals to the given value.

type JSONAssertFunc

type JSONAssertFunc func(json *AssertJSON)

JSONAssertFunc - callback function used for asserting JSON nodes.

type JWTAssertion added in v0.5.0

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

JWTAssertion is used to build a chain of assertions for the JWT node.

func IsJWT added in v0.7.0

func IsJWT(t TestingT, value string, keyFunc jwt.Keyfunc) *JWTAssertion

IsJWT asserts that the string contains valid JWT.

func (*JWTAssertion) Assert added in v0.5.0

func (a *JWTAssertion) Assert(assertFunc func(tb testing.TB, token *jwt.Token)) *JWTAssertion

Assert asserts that the JWT is satisfied by the user function assertFunc.

func (*JWTAssertion) Value added in v0.5.0

func (a *JWTAssertion) Value() *jwt.Token

Value returns decoded jwt.Token. If parsing fails it will return empty struct.

func (*JWTAssertion) WithAlgorithm added in v0.5.0

func (a *JWTAssertion) WithAlgorithm(alg string, msgAndArgs ...interface{}) *JWTAssertion

WithAlgorithm asserts that the JWT is signed with expected algorithm ("alg" header).

func (*JWTAssertion) WithAudience added in v0.5.0

func (a *JWTAssertion) WithAudience(expected []string, msgAndArgs ...interface{}) *JWTAssertion

WithAudience asserts that the JWT is has audience field ("aud" field in payload) with the expected values.

func (*JWTAssertion) WithExpiresAt added in v0.5.0

func (a *JWTAssertion) WithExpiresAt() *TimeAssertion

WithExpiresAt asserts that the JWT is has expired at field ("exp" field in payload). It runs TimeAssertion on its value.

func (*JWTAssertion) WithHeader added in v0.5.0

func (a *JWTAssertion) WithHeader(jsonAssert JSONAssertFunc) *JWTAssertion

WithHeader executes JSON assertion on JWT header.

func (*JWTAssertion) WithID added in v0.5.0

func (a *JWTAssertion) WithID(expected string, msgAndArgs ...interface{}) *JWTAssertion

WithID asserts that the JWT is has id field ("jti" field in payload) with the expected value.

func (*JWTAssertion) WithIssuedAt added in v0.5.0

func (a *JWTAssertion) WithIssuedAt() *TimeAssertion

WithIssuedAt asserts that the JWT is has issued at field ("iat" field in payload). It runs TimeAssertion on its value.

func (*JWTAssertion) WithIssuer added in v0.5.0

func (a *JWTAssertion) WithIssuer(expected string, msgAndArgs ...interface{}) *JWTAssertion

WithIssuer asserts that the JWT is has issuer field ("iss" field in payload) with the expected value.

func (*JWTAssertion) WithNotBefore added in v0.5.0

func (a *JWTAssertion) WithNotBefore() *TimeAssertion

WithNotBefore asserts that the JWT is has not before field ("nbf" field in payload). It runs TimeAssertion on its value.

func (*JWTAssertion) WithPayload added in v0.5.0

func (a *JWTAssertion) WithPayload(jsonAssert JSONAssertFunc) *JWTAssertion

WithPayload executes JSON assertion on JWT payload.

func (*JWTAssertion) WithSubject added in v0.5.0

func (a *JWTAssertion) WithSubject(expected string, msgAndArgs ...interface{}) *JWTAssertion

WithSubject asserts that the JWT is has subject field ("sub" field in payload) with the expected value.

type NumberAssertion added in v0.4.0

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

NumberAssertion is used to build a chain of assertions for the numeric node.

func (*NumberAssertion) EqualTo added in v0.4.0

func (a *NumberAssertion) EqualTo(expected float64, msgAndArgs ...interface{}) *NumberAssertion

EqualTo asserts that the JSON node has a numeric value equals to the given value.

func (*NumberAssertion) EqualToWithDelta added in v0.4.0

func (a *NumberAssertion) EqualToWithDelta(expected, delta float64, msgAndArgs ...interface{}) *NumberAssertion

EqualToWithDelta asserts that the JSON node has a numeric value equals to the given value with delta.

func (*NumberAssertion) GreaterThan added in v0.4.0

func (a *NumberAssertion) GreaterThan(expected float64, msgAndArgs ...interface{}) *NumberAssertion

GreaterThan asserts that the JSON node has a numeric value greater than the given value.

func (*NumberAssertion) GreaterThanOrEqual added in v0.4.0

func (a *NumberAssertion) GreaterThanOrEqual(expected float64, msgAndArgs ...interface{}) *NumberAssertion

GreaterThanOrEqual asserts that the JSON node has a numeric value greater than or equal to the given value.

func (*NumberAssertion) IsNotZero added in v0.7.0

func (a *NumberAssertion) IsNotZero(msgAndArgs ...interface{}) *NumberAssertion

IsNotZero asserts that the JSON node has a numeric value not equals to zero.

func (*NumberAssertion) IsZero added in v0.7.0

func (a *NumberAssertion) IsZero(msgAndArgs ...interface{}) *NumberAssertion

IsZero asserts that the JSON node has a numeric value equals to zero.

func (*NumberAssertion) LessThan added in v0.4.0

func (a *NumberAssertion) LessThan(expected float64, msgAndArgs ...interface{}) *NumberAssertion

LessThan asserts that the JSON node has a numeric value less than the given value.

func (*NumberAssertion) LessThanOrEqual added in v0.4.0

func (a *NumberAssertion) LessThanOrEqual(expected float64, msgAndArgs ...interface{}) *NumberAssertion

LessThanOrEqual asserts that the JSON node has a numeric value less than or equal to the given value.

func (*NumberAssertion) NotEqualTo added in v0.4.2

func (a *NumberAssertion) NotEqualTo(expected float64, msgAndArgs ...interface{}) *NumberAssertion

NotEqualTo asserts that the JSON node has a numeric value not equals to the given value.

type ObjectAssertion added in v0.4.0

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

ObjectAssertion is used to build a chain of assertions for the object node.

func (*ObjectAssertion) PropertiesCount added in v0.4.0

func (a *ObjectAssertion) PropertiesCount() int

PropertiesCount returns array underlying object properties count.

func (*ObjectAssertion) WithPropertiesCount added in v0.4.0

func (a *ObjectAssertion) WithPropertiesCount(expected int, msgAndArgs ...interface{}) *ObjectAssertion

WithPropertiesCount asserts that the JSON node is an object with properties count equal to the given value.

func (*ObjectAssertion) WithPropertiesCountGreaterThan added in v0.4.0

func (a *ObjectAssertion) WithPropertiesCountGreaterThan(expected int, msgAndArgs ...interface{}) *ObjectAssertion

WithPropertiesCountGreaterThan asserts that the JSON node is an object with properties count greater than the value.

func (*ObjectAssertion) WithPropertiesCountGreaterThanOrEqual added in v0.4.0

func (a *ObjectAssertion) WithPropertiesCountGreaterThanOrEqual(expected int, msgAndArgs ...interface{}) *ObjectAssertion

WithPropertiesCountGreaterThanOrEqual asserts that the JSON node is an object with propertiesCount greater than or equal to the value.

func (*ObjectAssertion) WithPropertiesCountLessThan added in v0.4.0

func (a *ObjectAssertion) WithPropertiesCountLessThan(expected int, msgAndArgs ...interface{}) *ObjectAssertion

WithPropertiesCountLessThan asserts that the JSON node is an object with properties count less than the value.

func (*ObjectAssertion) WithPropertiesCountLessThanOrEqual added in v0.4.0

func (a *ObjectAssertion) WithPropertiesCountLessThanOrEqual(expected int, msgAndArgs ...interface{}) *ObjectAssertion

WithPropertiesCountLessThanOrEqual asserts that the JSON node is an object with properties count less than or equal to the value.

func (*ObjectAssertion) WithUniqueElements added in v0.4.0

func (a *ObjectAssertion) WithUniqueElements(msgAndArgs ...interface{}) *ObjectAssertion

WithUniqueElements asserts that the JSON node is an object with unique elements.

type StringAssertion added in v0.4.0

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

StringAssertion is used to build a chain of assertions for the string node.

func (*StringAssertion) Assert added in v0.4.0

func (a *StringAssertion) Assert(assertFunc func(tb testing.TB, value string)) *StringAssertion

Assert asserts that the string node has that is satisfied by the user function assertFunc.

func (*StringAssertion) Contains added in v0.4.0

func (a *StringAssertion) Contains(value string, msgAndArgs ...interface{}) *StringAssertion

Contains asserts that the JSON node has a string value that contains a string.

func (*StringAssertion) EqualTo added in v0.4.0

func (a *StringAssertion) EqualTo(expectedValue string, msgAndArgs ...interface{}) *StringAssertion

EqualTo asserts that the JSON node has a string value equals to the given value.

func (*StringAssertion) EqualToOneOf added in v0.4.2

func (a *StringAssertion) EqualToOneOf(expectedValues ...string) *StringAssertion

EqualToOneOf asserts that the JSON node has a string value equals to one of the given values.

func (*StringAssertion) IsEmpty added in v0.7.0

func (a *StringAssertion) IsEmpty(msgAndArgs ...interface{}) *StringAssertion

IsEmpty asserts that the JSON node has a string value equals to empty string.

func (*StringAssertion) IsNotEmpty added in v0.7.0

func (a *StringAssertion) IsNotEmpty(msgAndArgs ...interface{}) *StringAssertion

IsNotEmpty asserts that the JSON node has a string value not equals to empty string.

func (*StringAssertion) Matches added in v0.4.0

func (a *StringAssertion) Matches(regexp interface{}, msgAndArgs ...interface{}) *StringAssertion

Matches asserts that the JSON node has a string value that matches the regular expression.

func (*StringAssertion) NotContains added in v0.4.0

func (a *StringAssertion) NotContains(value string, msgAndArgs ...interface{}) *StringAssertion

NotContains asserts that the JSON node has a string value that does not contain a string.

func (*StringAssertion) NotEqualTo added in v0.4.2

func (a *StringAssertion) NotEqualTo(expectedValue string, msgAndArgs ...interface{}) *StringAssertion

NotEqualTo asserts that the JSON node has a string value not equals to the given value.

func (*StringAssertion) NotMatches added in v0.4.0

func (a *StringAssertion) NotMatches(regexp interface{}, msgAndArgs ...interface{}) *StringAssertion

NotMatches asserts that the JSON node has a string value that does not match the regular expression.

func (*StringAssertion) That added in v0.4.0

func (a *StringAssertion) That(f func(s string) error, msgAndArgs ...interface{}) *StringAssertion

That asserts that the JSON node has a string value that is satisfied by callback function.

func (*StringAssertion) WithDate added in v0.5.0

func (a *StringAssertion) WithDate(msgAndArgs ...interface{}) *TimeAssertion

WithDate asserts that the JSON node has a string value with date in "YYYY-MM-DD" format.

func (*StringAssertion) WithEmail added in v0.4.1

func (a *StringAssertion) WithEmail(msgAndArgs ...interface{}) *StringAssertion

WithEmail asserts that the JSON node has a string value with email. Validation is based on simplified pattern. It allows all values with an "@" symbol in, and a "." in the second host part of the email address.

func (*StringAssertion) WithHTML5Email added in v0.4.1

func (a *StringAssertion) WithHTML5Email(msgAndArgs ...interface{}) *StringAssertion

WithHTML5Email asserts that the JSON node has a string value with email. Validation is based on pattern for HTML5 (see https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).

func (*StringAssertion) WithJSON added in v0.5.0

func (a *StringAssertion) WithJSON(jsonAssert JSONAssertFunc) *StringAssertion

WithJSON asserts that the JSON node has a string value with JSON.

func (*StringAssertion) WithJWT added in v0.5.0

func (a *StringAssertion) WithJWT(keyFunc jwt.Keyfunc, msgAndArgs ...interface{}) *JWTAssertion

WithJWT asserts that the JSON node has a string value with JWT.

func (*StringAssertion) WithLength added in v0.4.0

func (a *StringAssertion) WithLength(length int, msgAndArgs ...interface{}) *StringAssertion

WithLength asserts that the JSON node has a string value with length equal to the given value.

func (*StringAssertion) WithLengthGreaterThan added in v0.4.0

func (a *StringAssertion) WithLengthGreaterThan(expected int, msgAndArgs ...interface{}) *StringAssertion

WithLengthGreaterThan asserts that the JSON node has a string value with length greater than the value.

func (*StringAssertion) WithLengthGreaterThanOrEqual added in v0.4.0

func (a *StringAssertion) WithLengthGreaterThanOrEqual(expected int, msgAndArgs ...interface{}) *StringAssertion

WithLengthGreaterThanOrEqual asserts that the JSON node has a string value with length greater than or equal to the value.

func (*StringAssertion) WithLengthLessThan added in v0.4.0

func (a *StringAssertion) WithLengthLessThan(expected int, msgAndArgs ...interface{}) *StringAssertion

WithLengthLessThan asserts that the JSON node has a string value with length less than the value.

func (*StringAssertion) WithLengthLessThanOrEqual added in v0.4.0

func (a *StringAssertion) WithLengthLessThanOrEqual(expected int, msgAndArgs ...interface{}) *StringAssertion

WithLengthLessThanOrEqual asserts that the JSON node has a string value with length less than or equal to the value.

func (*StringAssertion) WithTime added in v0.5.0

func (a *StringAssertion) WithTime(msgAndArgs ...interface{}) *TimeAssertion

WithTime asserts that the JSON node has a string value with time in RFC3339 format.

func (*StringAssertion) WithTimeWithLayout added in v0.5.0

func (a *StringAssertion) WithTimeWithLayout(layout string, msgAndArgs ...interface{}) *TimeAssertion

WithTimeWithLayout asserts that the JSON node has a string value with time with the given layout.

func (*StringAssertion) WithURL added in v0.4.1

func (a *StringAssertion) WithURL(msgAndArgs ...interface{}) *URLAssertion

WithURL asserts that the JSON node has a string value with URL.

func (*StringAssertion) WithUUID added in v0.4.0

func (a *StringAssertion) WithUUID(msgAndArgs ...interface{}) *UUIDAssertion

WithUUID asserts that the JSON node has a string value with UUID.

type TestingT added in v0.4.0

type TestingT interface {
	Helper()
	Errorf(format string, args ...interface{})
	Log(args ...interface{})
}

TestingT is an interface wrapper around *testing.T.

type TimeAssertion added in v0.5.0

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

TimeAssertion is used to build a chain of assertions for the time node.

func (*TimeAssertion) After added in v0.5.0

func (a *TimeAssertion) After(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

After asserts that the JSON node is time after the given time.

func (*TimeAssertion) AfterDate added in v0.5.0

func (a *TimeAssertion) AfterDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

AfterDate asserts that the JSON node is time after the given date.

func (*TimeAssertion) AfterOrEqualTo added in v0.5.0

func (a *TimeAssertion) AfterOrEqualTo(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

AfterOrEqualTo asserts that the JSON node is time after or equal to the given time.

func (*TimeAssertion) AfterOrEqualToDate added in v0.5.0

func (a *TimeAssertion) AfterOrEqualToDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

AfterOrEqualToDate asserts that the JSON node is time after or equal to the given date.

func (*TimeAssertion) AtDate added in v0.6.0

func (a *TimeAssertion) AtDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

AtDate asserts that the JSON node is time between the beginning and the end of the given date.

func (*TimeAssertion) Before added in v0.5.0

func (a *TimeAssertion) Before(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

Before asserts that the JSON node is time before the given time.

func (*TimeAssertion) BeforeDate added in v0.5.0

func (a *TimeAssertion) BeforeDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

BeforeDate asserts that the JSON node is time before the given date.

func (*TimeAssertion) BeforeOrEqualTo added in v0.5.0

func (a *TimeAssertion) BeforeOrEqualTo(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

BeforeOrEqualTo asserts that the JSON node is time before or equal to the given time.

func (*TimeAssertion) BeforeOrEqualToDate added in v0.5.0

func (a *TimeAssertion) BeforeOrEqualToDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

BeforeOrEqualToDate asserts that the JSON node is time before or equal to the given date.

func (*TimeAssertion) EqualTo added in v0.5.0

func (a *TimeAssertion) EqualTo(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

EqualTo asserts that the JSON node is time equals to the given value.

func (*TimeAssertion) EqualToDate added in v0.5.0

func (a *TimeAssertion) EqualToDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

EqualToDate asserts that the JSON node is time equals to the given date.

func (*TimeAssertion) NotEqualTo added in v0.5.0

func (a *TimeAssertion) NotEqualTo(expected time.Time, msgAndArgs ...interface{}) *TimeAssertion

NotEqualTo asserts that the JSON node is time not equals to the given value.

func (*TimeAssertion) NotEqualToDate added in v0.5.0

func (a *TimeAssertion) NotEqualToDate(year int, month time.Month, day int, msgAndArgs ...interface{}) *TimeAssertion

NotEqualToDate asserts that the JSON node is time not equals to the given date.

func (*TimeAssertion) Value added in v0.5.0

func (a *TimeAssertion) Value() time.Time

Value returns JSON node value as time.Time. If string is not a valid time it returns empty time.

type URLAssertion added in v0.4.0

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

URLAssertion is used to build a chain of assertions for the URL node.

func (*URLAssertion) That added in v0.4.0

func (a *URLAssertion) That(f func(u *url.URL) error, msgAndArgs ...interface{}) *URLAssertion

That asserts that the JSON node has a URL value that is satisfied by callback function.

func (*URLAssertion) WithHosts added in v0.4.0

func (a *URLAssertion) WithHosts(hosts ...string) *URLAssertion

WithHosts additionally asserts than URL host contains one of the given values.

func (*URLAssertion) WithSchemas added in v0.4.0

func (a *URLAssertion) WithSchemas(schemas ...string) *URLAssertion

WithSchemas additionally asserts than URL schema contains one of the given values.

type UUIDAssertion added in v0.4.0

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

UUIDAssertion is used to build a chain of assertions for the UUID node.

func (*UUIDAssertion) EqualTo added in v0.4.0

func (a *UUIDAssertion) EqualTo(expected uuid.UUID, msgAndArgs ...interface{}) *UUIDAssertion

EqualTo asserts that the JSON node is UUID equals to the given value.

func (*UUIDAssertion) IsNil added in v0.5.0

func (a *UUIDAssertion) IsNil(msgAndArgs ...interface{}) *UUIDAssertion

IsNil asserts that the JSON node has a string value equals to nil UUID.

func (*UUIDAssertion) IsNotNil added in v0.5.0

func (a *UUIDAssertion) IsNotNil(msgAndArgs ...interface{}) *UUIDAssertion

IsNotNil asserts that the JSON node has a string value equals to not nil UUID.

func (*UUIDAssertion) Nil added in v0.4.0

func (a *UUIDAssertion) Nil(msgAndArgs ...interface{}) *UUIDAssertion

Nil asserts that the JSON node has a string value equals to nil UUID. Deprecated: use IsNil().

func (*UUIDAssertion) NotEqualTo added in v0.4.2

func (a *UUIDAssertion) NotEqualTo(expected uuid.UUID, msgAndArgs ...interface{}) *UUIDAssertion

NotEqualTo asserts that the JSON node is UUID not equals to the given value.

func (*UUIDAssertion) NotNil added in v0.4.0

func (a *UUIDAssertion) NotNil(msgAndArgs ...interface{}) *UUIDAssertion

NotNil asserts that the JSON node has a string value equals to not nil UUID. Deprecated: use IsNotNil().

func (*UUIDAssertion) OfVariant added in v0.5.0

func (a *UUIDAssertion) OfVariant(variant byte, msgAndArgs ...interface{}) *UUIDAssertion

OfVariant asserts that the JSON node has a string value equals to UUID with the given variant.

func (*UUIDAssertion) OfVersion added in v0.5.0

func (a *UUIDAssertion) OfVersion(version byte, msgAndArgs ...interface{}) *UUIDAssertion

OfVersion asserts that the JSON node has a string value equals to UUID with the given version.

func (*UUIDAssertion) Value added in v0.4.0

func (a *UUIDAssertion) Value() uuid.UUID

Value returns JSON node value as UUID. If string is not a valid UUID it returns nil UUID.

func (*UUIDAssertion) Variant added in v0.4.0

func (a *UUIDAssertion) Variant(variant byte, msgAndArgs ...interface{}) *UUIDAssertion

Variant asserts that the JSON node has a string value equals to UUID with the given variant. Deprecated: use OfVariant().

func (*UUIDAssertion) Version added in v0.4.0

func (a *UUIDAssertion) Version(version byte, msgAndArgs ...interface{}) *UUIDAssertion

Version asserts that the JSON node has a string value equals to UUID with the given version. Deprecated: use OfVersion().

Jump to

Keyboard shortcuts

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