testHelper

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package testHelper provides helper functions for testing purposes. Copyright (c) APIMatic. All rights reserved.

Index

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

func CheckResponseStatusCode(t *testing.T, respStatus int, expectedStatus int)

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

func IsSameAsFile(test *testing.T, expectedFileURL string, responseFileBytes []byte)

IsSameAsFile checks if the responseFileBytes is the same as the content of the file fetched from the expectedFileURL.

func IsSameInputBytes

func IsSameInputBytes(test *testing.T, expectedBytes []byte, receivedBytes []byte)

IsSameInputBytes checks if the receivedBytes are equal to the expectedBytes.

func KeysAndValuesBodyMatcher

func KeysAndValuesBodyMatcher(test *testing.T, expectedBody string, responseBody io.ReadCloser, checkArrayCount, checkArrayOrder bool)

KeysAndValuesBodyMatcher Checks whether the response body contains the same keys and values as those specified in the expected body. The keys and values provided can be a subset of the response being received. If any key or value is absent in the response body, the test fails. The test generated will perform deep checking which means if the response object contains nested objects, their keys and values will also be tested. In case of nested arrays, their ordering and strictness depends on the provided options.

func KeysBodyMatcher

func KeysBodyMatcher(test *testing.T, expectedBody string, responseBody io.ReadCloser, checkArrayCount, checkArrayOrder bool)

KeysBodyMatcher Checks whether the response body contains the same keys as those specified in the expected body. The keys provided can be a subset of the response being received. If any key is absent in the response body, the test fails. The test generated will perform deep checking which means if the response object contains nested objects, their keys will also be tested.

func NativeBodyMatcher

func NativeBodyMatcher(test *testing.T, expectedBody string, responseBody io.ReadCloser, isArray, checkArrayCount bool)

NativeBodyMatcher compares the response body as a primitive type(int, int64, float64, bool & time.Time) using a simple equality test. Response must match exactly except in case of arrays where array ordering and strictness can be controlled via other options.

func RawBodyMatcher

func RawBodyMatcher(test *testing.T, expectedBody string, responseBody io.ReadCloser)

RawBodyMatcher compares the response body with the expected body via simple string checking. In case of Binary response, byte-by-byte comparison is performed.

func SliceToCommaSeparatedString

func SliceToCommaSeparatedString(slice any) 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.

Jump to

Keyboard shortcuts

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