requirejson

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(t *testing.T, jsonData []byte, jsonObject string, msgAndArgs ...interface{})

Contains check if the json object is a subset of the jsonData. If the output doesn't match the test fails. If msgAndArgs are provided they will be used to explain the error.

func Empty

func Empty(t *testing.T, jsonData []byte, msgAndArgs ...interface{})

Empty check if the size of the json object is zero. If the lenght is not zero the test fails. If msgAndArgs are provided they will be used to explain the error.

func Len

func Len(t *testing.T, jsonData []byte, expectedLen int, msgAndArgs ...interface{})

Len check if the size of the json object match the given value. If the lenght doesn't match the test fails. If msgAndArgs are provided they will be used to explain the error.

func NotContains

func NotContains(t *testing.T, jsonData []byte, jsonObject string, msgAndArgs ...interface{})

NotContains check if the json object is NOT a subset of the jsonData. If the output match the test fails. If msgAndArgs are provided they will be used to explain the error.

func NotEmpty

func NotEmpty(t *testing.T, jsonData []byte, msgAndArgs ...interface{})

NotEmpty check if the size of the json object is not zero. If the lenght is zero the test fails. If msgAndArgs are provided they will be used to explain the error.

func Query

func Query(t *testing.T, jsonData []byte, jqQuery string, jsonExpected string, msgAndArgs ...interface{})

Query performs a test on a given json output. A jq-like query is performed on the given jsonData and the result is compared with jsonExpected. If the output doesn't match the test fails. If msgAndArgs are provided they will be used to explain the error.

Types

type JQObject added in v1.1.0

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

JQObject is an object that abstract operations on JSON data.

func Parse added in v1.1.0

func Parse(t *testing.T, jsonData []byte, msgAndArgs ...interface{}) *JQObject

Parse creates a new JQObect from the given jsonData. If jsonData is not a valid json the test fails.

func ParseFromFile added in v1.3.0

func ParseFromFile(t *testing.T, filePath string, msgAndArgs ...interface{}) *JQObject

ParseFromFile creates a new JQObect from the given file path. If the file is not a valid json the test fails.

func (*JQObject) ArrayMustContain added in v1.2.0

func (obj *JQObject) ArrayMustContain(jsonElement string, msgAndArgs ...interface{})

ArrayMustContain checks if the give JQObject contains the given element.

func (*JQObject) IsFalse added in v1.2.0

func (obj *JQObject) IsFalse(msgAndArgs ...interface{})

IsFalse test if the JQObject is `false`.

func (*JQObject) IsTrue added in v1.2.0

func (obj *JQObject) IsTrue(msgAndArgs ...interface{})

IsTrue test if the JQObject is `true`.

func (*JQObject) LengthMustEqualTo added in v1.1.0

func (obj *JQObject) LengthMustEqualTo(expectedLen int, msgAndArgs ...interface{})

LengthMustEqualTo tests if the size of JQObject match expectedLen. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) MustBeEmpty added in v1.1.0

func (obj *JQObject) MustBeEmpty(msgAndArgs ...interface{})

MustBeEmpty test if the size of JQObject is 0. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) MustContain added in v1.1.0

func (obj *JQObject) MustContain(jsonExpected string, msgAndArgs ...interface{})

MustContain tests if jsonExpected is a subset of the JQObject. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) MustEqual added in v1.1.0

func (obj *JQObject) MustEqual(jsonExpected string, msgAndArgs ...interface{})

MustEqual tests if the JQObject equals jsonExpected. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) MustNotBeEmpty added in v1.1.0

func (obj *JQObject) MustNotBeEmpty(msgAndArgs ...interface{})

MustNotBeEmpty test if the size of JQObject is not 0. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) MustNotContain added in v1.1.0

func (obj *JQObject) MustNotContain(jsonExpected string, msgAndArgs ...interface{})

MustNotContain tests if the JQObject does not contain jsonExpected. If the check is not successful the test will fail. If msgAndArgs are provided they will be used to explain the error.

func (*JQObject) Query added in v1.1.0

func (obj *JQObject) Query(jqQuery string) *JQObject

Query performs a query on the given JQObject and returns the first result. If the query produces no result the test will fail.

func (*JQObject) String added in v1.1.0

func (obj *JQObject) String() string

Jump to

Keyboard shortcuts

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