Documentation
¶
Overview ¶
Package testHelper provides helper functions for testing purposes. Copyright (c) APIMatic. All rights reserved.
Index ¶
- func CheckResponseHeaders(t *testing.T, responseHeaders http.Header, expectedHeadersList []TestHeader, ...)
- func CheckResponseStatusCode(t *testing.T, respStatus int, expectedStatus int)
- func CheckResponseStatusRange(t *testing.T, respStatus int, expectedLowerLimit int, expectedUpperLimit int)
- func IsSameAsFile(test *testing.T, expectedFileURL string, responseFileBytes []byte)
- func IsSameInputBytes(test *testing.T, expectedBytes []byte, receivedBytes []byte)
- func KeysAndValuesBodyMatcher(test *testing.T, expectedBody string, responseObject any, ...)
- func KeysBodyMatcher(test *testing.T, expectedBody string, responseObject any, ...)
- func NativeBodyMatcher(test *testing.T, expectedBody string, responseObject any)
- func RawBodyMatcher(test *testing.T, expectedBody string, responseObject any)
- func SliceToCommaSeparatedString(slice interface{}) string
- type TestHeader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckResponseHeaders ¶
func CheckResponseHeaders(t *testing.T, responseHeaders http.Header, expectedHeadersList []TestHeader, allowExtraHeaders bool)
CheckResponseHeaders checks if the responseHeaders contain the expected headers specified in expectedHeadersList. If allowExtraHeaders is set to false, it also verifies that no extra headers are present in the responseHeaders.
func CheckResponseStatusCode ¶
CheckResponseStatusCode checks if the actual response status code matches the expected status code. If they do not match, it reports an error with the actual and expected status codes.
func CheckResponseStatusRange ¶
func CheckResponseStatusRange(t *testing.T, respStatus int, expectedLowerLimit int, expectedUpperLimit int)
CheckResponseStatusRange checks if the actual response status code falls within the expected range (inclusive). If the actual status code is not within the range, it reports an error with the actual status code and the expected range.
func IsSameAsFile ¶
IsSameAsFile checks if the responseFileBytes is the same as the content of the file fetched from the expectedFileURL.
func IsSameInputBytes ¶
IsSameInputBytes checks if the receivedBytes are equal to the expectedBytes.
func KeysAndValuesBodyMatcher ¶
func KeysAndValuesBodyMatcher(test *testing.T, expectedBody string, responseObject any, checkArrayCount, checkArrayOrder bool)
KeysAndValuesBodyMatcher compares the JSON response body with the expected JSON body using keys and values. The responseObject and expectedBody should have the same keys and their corresponding values should be equal.
func KeysBodyMatcher ¶
func KeysBodyMatcher(test *testing.T, expectedBody string, responseObject any, checkArrayCount, checkArrayOrder bool)
KeysBodyMatcher compares the JSON response body with the expected JSON body using keys only. The responseObject and expectedBody should have the same keys.
func NativeBodyMatcher ¶
NativeBodyMatcher compares the JSON response body with the expected JSON body.
func RawBodyMatcher ¶
RawBodyMatcher checks if the expectedBody is contained within the JSON response body.
func SliceToCommaSeparatedString ¶
func SliceToCommaSeparatedString(slice interface{}) string
SliceToCommaSeparatedString converts a slice to a comma-separated string representation.
Types ¶
type TestHeader ¶
type TestHeader struct {
CheckValue bool `json:"CheckValue"`
Name string `json:"Name"`
Value string `json:"Value"`
}
TestHeader represents a test header with Name, Value, and CheckValue fields.
func NewTestHeader ¶
func NewTestHeader(checkValue bool, name, value string) TestHeader
NewTestHeader creates and returns a new TestHeader with the given values.