testing

package
v1.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testing provides utilities for testing smith clients and protocols.

Index

Constants

View Source
const (
	GZIP = "gzip"
)

Enumeration values for supported compress Algorithms.

Variables

This section is empty.

Functions

func AssertHasHeader

func AssertHasHeader(t T, expect, actual http.Header) bool

AssertHasHeader compares the header values and identifies if the actual header set includes all values specified in the expect set. Emits a testing error, and returns false if the headers are not equal.

func AssertHasHeaderKeys

func AssertHasHeaderKeys(t T, keys []string, actual http.Header) bool

AssertHasHeaderKeys validates that header set contains all keys expected. Emits a testing error, and returns false if the headers are not equal.

func AssertHasQuery

func AssertHasQuery(t T, expect, actual []QueryItem) bool

AssertHasQuery validates that the expected set of query items are present in the actual set. Emits a testing error, and returns false if any of the expected set are not found in the actual.

func AssertHasQueryKeys

func AssertHasQueryKeys(t T, keys []string, actual []QueryItem) bool

AssertHasQueryKeys validates that the actual set of query items contains the keys provided. Emits a testing error if any key is not found.

func AssertJSONEqual

func AssertJSONEqual(t T, expect, actual []byte) bool

AssertJSONEqual compares two JSON documents and identifies if the documents contain the same values. Emits a testing error, and returns false if the documents are not equal.

func AssertNotHaveHeaderKeys

func AssertNotHaveHeaderKeys(t T, keys []string, actual http.Header) bool

AssertNotHaveHeaderKeys validates that header set does not contains any of the keys. Emits a testing error, and returns false if the header contains the any of the keys equal.

func AssertNotHaveQueryKeys

func AssertNotHaveQueryKeys(t T, keys []string, actual []QueryItem) bool

AssertNotHaveQueryKeys validates that the actual set of query items does not contains the keys provided. Emits a testing error if any key is found.

func AssertURLFormEqual

func AssertURLFormEqual(t T, expect, actual []byte) bool

AssertURLFormEqual compares two URLForm documents and identifies if the documents contain the same values. Emits a testing error, and returns false if the documents are not equal.

func AssertXMLEqual

func AssertXMLEqual(t T, expect, actual []byte) bool

AssertXMLEqual compares two XML documents and identifies if the documents contain the same values. Emits a testing error, and returns false if the documents are not equal.

func CompareCBOR added in v1.20.2

func CompareCBOR(actual io.Reader, expect64 string) error

CompareCBOR checks whether two CBOR values are equivalent.

The function signature is tailored for use in smithy protocol tests, where the expected encoding is given in base64, and the actual value to check is passed from the mock HTTP request body.

func CompareCompressedBytes added in v1.19.0

func CompareCompressedBytes(expect *bytes.Buffer, actual io.Reader, disable bool, min int64, algorithm string) error

CompareCompressedBytes compares the request stream before and after possible request compression

func CompareJSONReaderBytes

func CompareJSONReaderBytes(r io.Reader, expect []byte) error

CompareJSONReaderBytes compares the reader containing serialized JSON document. Deserializes the JSON documents to determine if they are equal. Return an error if the two JSON documents are not equal.

func CompareReaderBytes

func CompareReaderBytes(r io.Reader, expect []byte) error

CompareReaderBytes compares the reader with the expected bytes. Returns an error if the two bytes are not equal.

func CompareReaderEmpty

func CompareReaderEmpty(r io.Reader) error

CompareReaderEmpty checks if the reader is nil, or contains no bytes. Returns an error if not empty.

func CompareReaders

func CompareReaders(expect, actual io.Reader) error

CompareReaders two io.Reader values together to determine if they are equal. Will read the contents of the readers until they are empty.

func CompareURLFormReaderBytes

func CompareURLFormReaderBytes(r io.Reader, expect []byte) error

CompareURLFormReaderBytes compares the reader containing serialized URLForm document. Deserializes the URLForm documents to determine if they are equal. Return an error if the two URLForm documents are not equal.

func CompareValues

func CompareValues(expect, actual interface{}, _ ...interface{}) error

CompareValues compares two values to determine if they are equal, specialized for comparison of SDK operation output types.

CompareValues expects the two values to be of the same underlying type. Doing otherwise will result in undefined behavior.

The third variadic argument is vestigial from a previous implementation that depended on go-cmp. Values passed therein have no effect.

func CompareXMLReaderBytes

func CompareXMLReaderBytes(r io.Reader, expect []byte) error

CompareXMLReaderBytes compares the reader with expected xml byte

func GzipCompareCompressBytes added in v1.19.0

func GzipCompareCompressBytes(expect []byte, actual io.Reader) error

func HasHeader

func HasHeader(expect, actual http.Header) error

HasHeader compares the header values and identifies if the actual header set includes all values specified in the expect set. Returns an error if not.

func HasHeaderKeys

func HasHeaderKeys(keys []string, actual http.Header) error

HasHeaderKeys validates that header set contains all keys expected. Returns an error if a header key is not in the header set.

func HasQuery

func HasQuery(expect, actual []QueryItem) error

HasQuery validates that the expected set of query items are present in the actual set. Returns an error if any of the expected set are not found in the actual.

func HasQueryKeys

func HasQueryKeys(keys []string, actual []QueryItem) error

HasQueryKeys validates that the actual set of query items contains the keys provided. Returns an error if any key is not found.

func JSONEqual

func JSONEqual(expectBytes, actualBytes []byte) error

JSONEqual compares two JSON documents and identifies if the documents contain the same values. Returns an error if the two documents are not equal.

func NotHaveHeaderKeys

func NotHaveHeaderKeys(keys []string, actual http.Header) error

NotHaveHeaderKeys validates that header set does not contains any of the keys. Returns an error if a header key is found in the header set.

func NotHaveQueryKeys

func NotHaveQueryKeys(keys []string, actual []QueryItem) error

NotHaveQueryKeys validates that the actual set of query items does not contain the keys provided. Returns an error if any key is found.

func URLFormEqual

func URLFormEqual(expectBytes, actualBytes []byte) error

URLFormEqual compares two URLForm documents and identifies if the documents contain the same values. Returns an error if the two documents are not equal.

func XMLEqual

func XMLEqual(expectBytes, actualBytes []byte) error

XMLEqual asserts two xml documents by sorting the XML and comparing the strings It returns an error in case of mismatch or in case of malformed xml found while sorting. In case of mismatched XML, the error string will contain the diff between the two XMLs.

Types

type ByteLoop

type ByteLoop struct {
	// contains filtered or unexported fields
}

ByteLoop provides an io.ReadCloser that always fills the read byte slice with repeating value, until closed.

func (*ByteLoop) Close

func (l *ByteLoop) Close() error

Close closes the ByteLoop, and prevents any further reading.

func (*ByteLoop) Read

func (l *ByteLoop) Read(p []byte) (size int, err error)

Read populates the passed in byte slice with the value the ByteLoop was created with. Returns the size of bytes written. If the reader is closed, io.EOF will be returned.

type QueryItem

type QueryItem struct {
	Key   string
	Value string
}

QueryItem provides an escaped key and value struct for values from a raw query string.

func ParseRawQuery

func ParseRawQuery(rawQuery string) (items []QueryItem)

ParseRawQuery returns a slice of QueryItems extracted from the raw query string. The parsed QueryItems preserve escaping of key and values.

All + escape characters are replaced with %20 for consistent escaping pattern.

type T

type T interface {
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Helper()
}

T provides the testing interface for capturing failures with testing assert utilities.

Directories

Path Synopsis
package xml is xml testing package that supports xml comparison utility.
package xml is xml testing package that supports xml comparison utility.

Jump to

Keyboard shortcuts

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