testutil

package
v0.0.0-...-6e52582 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertToken

func AssertToken(t *testing.T, tp auth.TokenProvider, expected string)

AssertToken calls Token() and checks it matches expected.

func CookieParamRef

func CookieParamRef(name, typ string, required bool) *openapi3.ParameterRef

CookieParamRef creates an OpenAPI cookie parameter reference.

func EmptyHandler

func EmptyHandler(status int) http.HandlerFunc

EmptyHandler returns an http.HandlerFunc that responds with just a status code and no body.

func ExpiredTokens

func ExpiredTokens(tokenEndpoint string) *auth.StoredTokens

ExpiredTokens returns a StoredTokens that already expired.

func ExpiringTokens

func ExpiringTokens(tokenEndpoint string) *auth.StoredTokens

ExpiringTokens returns a StoredTokens that expires within the refresh margin.

func FormURLEncodedBodyRef

func FormURLEncodedBodyRef(required bool) *openapi3.RequestBodyRef

FormURLEncodedBodyRef creates a request body with application/x-www-form-urlencoded.

func HeaderParamRef

func HeaderParamRef(name, typ string, required bool) *openapi3.ParameterRef

HeaderParamRef creates an OpenAPI header parameter reference.

func JSONBodyRef

func JSONBodyRef(required bool, schema *openapi3.Schema) *openapi3.RequestBodyRef

JSONBodyRef creates an OpenAPI request body with application/json content.

func JSONHandler

func JSONHandler(status int, body any) http.HandlerFunc

JSONHandler returns an http.HandlerFunc that responds with the given status and JSON body.

func MakeEndpoint

func MakeEndpoint(method, path string, opts ...EndpointOpt) spec.Endpoint

MakeEndpoint builds a test Endpoint with functional options.

func MinimalSpec

func MinimalSpec(paths map[string]*openapi3.PathItem) *openapi3.T

MinimalSpec returns a minimal valid OpenAPI 3.0 spec with the given paths.

func MockAPI

func MockAPI(t *testing.T, handlers map[string]http.HandlerFunc) *httptest.Server

MockAPI creates a test HTTP server that routes requests by "METHOD /path".

func MockTokenEndpoint

func MockTokenEndpoint(t *testing.T, accessToken, refreshToken string, expiresIn int) *httptest.Server

MockTokenEndpoint creates a test server that acts as an OIDC token endpoint.

func MockTokenProvider

func MockTokenProvider(token string) auth.TokenProvider

MockTokenProvider returns a TokenProvider that always returns the given token.

func MockWellKnown

func MockWellKnown(t *testing.T, authURL, tokenURL string) *httptest.Server

MockWellKnown creates a test server that serves an OIDC discovery document.

func MultipartBodyRef

func MultipartBodyRef(required bool) *openapi3.RequestBodyRef

MultipartBodyRef creates an OpenAPI request body with multipart/form-data content.

func PathParamRef

func PathParamRef(name, typ string, required bool) *openapi3.ParameterRef

PathParam creates an OpenAPI path parameter reference.

func QueryParamRef

func QueryParamRef(name, typ string, required bool) *openapi3.ParameterRef

QueryParamRef creates an OpenAPI query parameter reference.

func SimpleOperation

func SimpleOperation(summary string, params ...*openapi3.ParameterRef) *openapi3.Operation

SimpleOperation creates a basic operation with optional parameters.

func SimplePathItem

func SimplePathItem(method string, op *openapi3.Operation) *openapi3.PathItem

SimplePathItem creates a PathItem with a single operation on the given method.

func TextHandler

func TextHandler(status int, text string) http.HandlerFunc

TextHandler returns an http.HandlerFunc that responds with text/plain.

func ValidTokens

func ValidTokens(tokenEndpoint string) *auth.StoredTokens

ValidTokens returns a StoredTokens that won't expire for 1 hour.

func WriteSpecFile

func WriteSpecFile(t *testing.T, doc *openapi3.T) string

WriteSpecFile writes an OpenAPI spec to a temp YAML file and returns the path.

func WriteTempTokenFile

func WriteTempTokenFile(t *testing.T, tokens *auth.StoredTokens) string

WriteTempTokenFile creates a temp token file and returns its path.

Types

type EndpointOpt

type EndpointOpt func(*spec.Endpoint)

EndpointOpt is a functional option for building test Endpoints.

func WithBody

func WithBody(required bool, schema map[string]any) EndpointOpt

WithBody adds a request body with the given schema map.

func WithBodyContentType

func WithBodyContentType(required bool, contentType string, schema map[string]any) EndpointOpt

WithBodyContentType adds a request body with a specific content type.

func WithHeaderParam

func WithHeaderParam(name, typ string, required bool) EndpointOpt

WithHeaderParam adds a header parameter to the endpoint.

func WithPathParam

func WithPathParam(name, typ string, required bool) EndpointOpt

WithPathParam adds a path parameter to the endpoint.

func WithQueryParam

func WithQueryParam(name, typ string, required bool) EndpointOpt

WithQueryParam adds a query parameter to the endpoint.

func WithSummary

func WithSummary(s string) EndpointOpt

WithSummary sets the summary on the endpoint.

type RecordingHandler

type RecordingHandler struct {
	Requests []*http.Request
	Status   int
	Body     any
}

RecordingHandler captures the request for later inspection.

func (*RecordingHandler) ServeHTTP

func (rh *RecordingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

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