Documentation
¶
Index ¶
- func AssertToken(t *testing.T, tp auth.TokenProvider, expected string)
- func CookieParamRef(name, typ string, required bool) *openapi3.ParameterRef
- func EmptyHandler(status int) http.HandlerFunc
- func ExpiredTokens(tokenEndpoint string) *auth.StoredTokens
- func ExpiringTokens(tokenEndpoint string) *auth.StoredTokens
- func FormURLEncodedBodyRef(required bool) *openapi3.RequestBodyRef
- func HeaderParamRef(name, typ string, required bool) *openapi3.ParameterRef
- func JSONBodyRef(required bool, schema *openapi3.Schema) *openapi3.RequestBodyRef
- func JSONHandler(status int, body any) http.HandlerFunc
- func MakeEndpoint(method, path string, opts ...EndpointOpt) spec.Endpoint
- func MinimalSpec(paths map[string]*openapi3.PathItem) *openapi3.T
- func MockAPI(t *testing.T, handlers map[string]http.HandlerFunc) *httptest.Server
- func MockTokenEndpoint(t *testing.T, accessToken, refreshToken string, expiresIn int) *httptest.Server
- func MockTokenProvider(token string) auth.TokenProvider
- func MockWellKnown(t *testing.T, authURL, tokenURL string) *httptest.Server
- func MultipartBodyRef(required bool) *openapi3.RequestBodyRef
- func PathParamRef(name, typ string, required bool) *openapi3.ParameterRef
- func QueryParamRef(name, typ string, required bool) *openapi3.ParameterRef
- func SimpleOperation(summary string, params ...*openapi3.ParameterRef) *openapi3.Operation
- func SimplePathItem(method string, op *openapi3.Operation) *openapi3.PathItem
- func TextHandler(status int, text string) http.HandlerFunc
- func ValidTokens(tokenEndpoint string) *auth.StoredTokens
- func WriteSpecFile(t *testing.T, doc *openapi3.T) string
- func WriteTempTokenFile(t *testing.T, tokens *auth.StoredTokens) string
- type EndpointOpt
- func WithBody(required bool, schema map[string]any) EndpointOpt
- func WithBodyContentType(required bool, contentType string, schema map[string]any) EndpointOpt
- func WithHeaderParam(name, typ string, required bool) EndpointOpt
- func WithPathParam(name, typ string, required bool) EndpointOpt
- func WithQueryParam(name, typ string, required bool) EndpointOpt
- func WithSummary(s string) EndpointOpt
- type RecordingHandler
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 ¶
MinimalSpec returns a minimal valid OpenAPI 3.0 spec with the given paths.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RecordingHandler captures the request for later inspection.
func (*RecordingHandler) ServeHTTP ¶
func (rh *RecordingHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.