testHelper

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 7 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, 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

func NativeBodyMatcher(test *testing.T, expectedBody string, responseObject any)

NativeBodyMatcher compares the JSON response body with the expected JSON body.

func RawBodyMatcher

func RawBodyMatcher(test *testing.T, expectedBody string, responseObject any)

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.

Jump to

Keyboard shortcuts

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