apitest

package
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package apitest provides HTTP response assertions for application tests.

The package is stable core API for tests. It builds on httptest.ResponseRecorder semantics and complements contracttest: contracttest checks route registries and OpenAPI metadata, while apitest checks concrete HTTP responses emitted by handlers.

Use AssertProblem, AssertProblemCode, AssertValidationFields, AssertJSON, AssertHeader, AssertRateLimitHeaders, AssertETag, AssertDeprecationHeaders, AssertPagination, AssertOperationAccepted, AssertWebhookSignature, and AssertOpenAPIGolden to keep API tests focused on externally visible behavior.

These helpers call testing.TB.Fatal when assertions fail. They are not runtime middleware and should not be imported by production handlers. For examples, see docs/cookbook.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertDeprecationHeaders

func AssertDeprecationHeaders(t testing.TB, recorder *httptest.ResponseRecorder)

AssertDeprecationHeaders asserts runtime deprecation headers.

func AssertETag

func AssertETag(t testing.TB, recorder *httptest.ResponseRecorder, want string)

AssertETag asserts the ETag response header.

func AssertHeader

func AssertHeader(t testing.TB, recorder *httptest.ResponseRecorder, name, want string)

AssertHeader asserts a response header value.

func AssertJSON

func AssertJSON(t testing.TB, recorder *httptest.ResponseRecorder, want any)

AssertJSON asserts a JSON response body.

func AssertOpenAPIGolden

func AssertOpenAPIGolden(t testing.TB, got, golden []byte)

AssertOpenAPIGolden asserts normalized OpenAPI JSON against a golden document.

func AssertOperationAccepted

func AssertOperationAccepted(t testing.TB, recorder *httptest.ResponseRecorder, location string)

AssertOperationAccepted asserts a 202 operation response.

func AssertPagination

func AssertPagination(t testing.TB, recorder *httptest.ResponseRecorder, count, limit int)

AssertPagination asserts common list metadata values.

func AssertProblem

func AssertProblem(t testing.TB, recorder *httptest.ResponseRecorder, status int) map[string]any

AssertProblem asserts a Problem Details response and returns the decoded body.

func AssertProblemCode

func AssertProblemCode(t testing.TB, recorder *httptest.ResponseRecorder, code httpx.ProblemCode)

AssertProblemCode asserts a typed problem code extension.

func AssertRateLimitHeaders

func AssertRateLimitHeaders(t testing.TB, recorder *httptest.ResponseRecorder)

AssertRateLimitHeaders asserts standard quota headers exist.

func AssertValidationFields

func AssertValidationFields(t testing.TB, recorder *httptest.ResponseRecorder, fields ...string)

AssertValidationFields asserts validation field names in a Problem Details response.

func AssertWebhookSignature

func AssertWebhookSignature(t testing.TB, header http.Header, name string)

AssertWebhookSignature asserts that a signature header is present.

Types

This section is empty.

Jump to

Keyboard shortcuts

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