should

package
v0.0.0-...-891d188 Latest Latest
Warning

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

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

Documentation

Overview

Package should contains assertions for tests, which returns an error if the assertion fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckOff

func CheckOff(items []interface{}, wantItem interface{}) ([]interface{}, error)

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

func CheckOffAll

func CheckOffAll(items []interface{}, wantItems []interface{}) error

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

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

func CheckOffAllAllowUnwanted

func CheckOffAllAllowUnwanted(items []interface{}, wantItems []interface{}) ([]interface{}, error)

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, an error is returned Items are compared using match.JSONDeepEqual

func ContainSubset

func ContainSubset[V comparable](larger []V, smaller []V) error

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 GetJSONFieldStr

func GetJSONFieldStr(body gjson.Result, wantKey string) (string, error)

EXPERIMENTAL 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 GetTimelineEventIDs

func GetTimelineEventIDs(topLevelSyncJSON gjson.Result, roomID string) []string

EXPERIMENTAL GetTimelineEventIDs returns the timeline event IDs in the sync response for the given room ID. If the room is missing this returns a 0 element slice.

func HaveInOrder

func HaveInOrder[V comparable](gots []V, wants []V) error

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

func MatchFailure

func MatchFailure(res *http.Response) error

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

func MatchFederationRequest

func MatchFederationRequest(fedReq *fclient.FederationRequest, matchers ...match.JSON) error

MatchFederationRequest performs JSON assertions on incoming federation requests.

func MatchGJSON

func MatchGJSON(jsonResult gjson.Result, matchers ...match.JSON) error

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

func MatchJSONBytes

func MatchJSONBytes(rawJson []byte, matchers ...match.JSON) error

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

func MatchRequest

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

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

func MatchResponse

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

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

func MatchSuccess

func MatchSuccess(res *http.Response) error

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

func NotContainSubset

func NotContainSubset[V comparable](larger []V, smaller []V) error

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 ParseJSON

func ParseJSON(b io.ReadCloser) (res gjson.Result, err error)

EXPERIMENTAL ParseJSON will ensure that the HTTP request/response body is valid JSON, then return the body, else returns 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