must

package
v0.0.0-...-0332eaf Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package must contains assertions for tests, which fail the test if the assertion fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckOff

func CheckOff(t ct.TestLike, items []interface{}, wantItem interface{}) []interface{}

EXPERIMENTAL CheckOff an item from the list. If the item is not present the test is failed. The updated list with the matched item removed from it is returned. Items are compared using JSON deep equal.

func CheckOffAll

func CheckOffAll(t ct.TestLike, items []interface{}, wantItems []interface{})

EXPERIMENTAL CheckOffAll checks that a list contains exactly the given items, in any order.

if an item is not present, the test is failed. if an item not present in the want list is present, the test is failed. Items are compared using match.JSONDeepEqual

func CheckOffAllAllowUnwanted

func CheckOffAllAllowUnwanted(t ct.TestLike, items []interface{}, wantItems []interface{}) []interface{}

EXPERIMENTAL CheckOffAllAllowUnwanted checks that a list contains all of the given items, in any order. The updated list with the matched items removed from it is returned.

if an item is not present, the test is failed. Items are compared using match.JSONDeepEqual

func ContainSubset

func ContainSubset[V comparable](t ct.TestLike, larger []V, smaller []V)

EXPERIMENTAL ContainSubset checks that every item in smaller is in larger, failing the test if at least 1 item isn't. Ignores extra elements in larger. Ignores ordering.

func Equal

func Equal[V comparable](t ct.TestLike, got, want V, msg string)

Equal ensures that got==want else logs an error. The 'msg' is displayed with the error to provide extra context.

func GetJSONFieldStr

func GetJSONFieldStr(t ct.TestLike, body gjson.Result, wantKey string) string

GetJSONFieldStr extracts the string value under `wantKey` or fails the test. The format of `wantKey` is specified at https://godoc.org/github.com/tidwall/gjson#Get

func HaveInOrder

func HaveInOrder[V comparable](t ct.TestLike, gots []V, wants []V)

EXPERIMENTAL HaveInOrder checks that the two slices match exactly, failing the test on mismatches or omissions.

func MatchFailure

func MatchFailure(t ct.TestLike, res *http.Response)

EXPERIMENTAL MatchFailure consumes the HTTP response and fails if the response is 2xx.

func MatchFederationRequest

func MatchFederationRequest(t ct.TestLike, fedReq *fclient.FederationRequest, matchers ...match.JSON)

MatchFederationRequest performs JSON assertions on incoming federation requests.

func MatchGJSON

func MatchGJSON(t ct.TestLike, jsonResult gjson.Result, matchers ...match.JSON)

EXPERIMENTAL MatchGJSON performs JSON assertions on a gjson.Result object.

func MatchJSONBytes

func MatchJSONBytes(t ct.TestLike, rawJson []byte, matchers ...match.JSON)

EXPERIMENTAL MatchJSONBytes performs JSON assertions on a raw json byte slice.

func MatchRequest

func MatchRequest(t ct.TestLike, req *http.Request, m match.HTTPRequest) []byte

EXPERIMENTAL MatchRequest consumes the HTTP request and performs HTTP-level assertions on it. Returns the raw response body.

func MatchResponse

func MatchResponse(t ct.TestLike, res *http.Response, m match.HTTPResponse) []byte

EXPERIMENTAL MatchResponse consumes the HTTP response and performs HTTP-level assertions on it. Returns the raw response body.

func MatchSuccess

func MatchSuccess(t ct.TestLike, res *http.Response)

EXPERIMENTAL MatchSuccess consumes the HTTP response and fails if the response is non-2xx.

func NotContainSubset

func NotContainSubset[V comparable](t ct.TestLike, larger []V, smaller []V)

EXPERIMENTAL NotContainSubset checks that every item in smaller is NOT in larger, failing the test if at least 1 item is. Ignores extra elements in larger. Ignores ordering.

func NotEqual

func NotEqual[V comparable](t ct.TestLike, got, want V, msg string)

NotEqual ensures that got!=want else logs an error. The 'msg' is displayed with the error to provide extra context.

func NotError

func NotError(t ct.TestLike, msg string, err error)

NotError will ensure `err` is nil else terminate the test with `msg`.

func ParseJSON

func ParseJSON(t ct.TestLike, b io.ReadCloser) gjson.Result

EXPERIMENTAL ParseJSON will ensure that the HTTP request/response body is valid JSON, then return the body, else terminate the test.

func StartWithStr

func StartWithStr(t ct.TestLike, got, wantPrefix, msg string)

EXPERIMENTAL StartWithStr ensures that got starts with wantPrefix else logs an error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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