gpptest

package
v1.11.8 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gpptest provides typed helpers for exercising gpp applications through httptest without opening network sockets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](response *ResponseWrapper) T

Decode parses a response JSON body into T and fails the active test on error.

func ParseProblemDetails

func ParseProblemDetails(body []byte) (gpp.ProblemDetails, error)

ParseProblemDetails strictly decodes one valid RFC 7807 document.

Types

type ResponseWrapper

type ResponseWrapper struct {
	Recorder *httptest.ResponseRecorder
	// contains filtered or unexported fields
}

ResponseWrapper wraps httptest.ResponseRecorder with ergonomic assertion helpers.

func (*ResponseWrapper) AssertContains

func (r *ResponseWrapper) AssertContains(substring string) *ResponseWrapper

AssertContains asserts that the response body contains a expected substring.

func (*ResponseWrapper) AssertContentType

func (r *ResponseWrapper) AssertContentType(expected string) *ResponseWrapper

AssertContentType verifies the parsed response media type.

func (*ResponseWrapper) AssertHeader

func (r *ResponseWrapper) AssertHeader(name, expected string) *ResponseWrapper

AssertHeader verifies an exact response header value.

func (*ResponseWrapper) AssertJSON

func (r *ResponseWrapper) AssertJSON(key string, expected any) *ResponseWrapper

AssertJSON asserts that a JSON field in the response body equals the expected value.

func (*ResponseWrapper) AssertJSONPath

func (r *ResponseWrapper) AssertJSONPath(path string, expected any) *ResponseWrapper

AssertJSONPath verifies a dot-separated object or array path in a JSON response.

func (*ResponseWrapper) AssertProblem

func (r *ResponseWrapper) AssertProblem(status int, problemType string) *ResponseWrapper

AssertProblem verifies the HTTP and problem status plus an optional problem type.

func (*ResponseWrapper) AssertRequestID

func (r *ResponseWrapper) AssertRequestID() *ResponseWrapper

AssertRequestID verifies response correlation and Problem Details trace IDs.

func (*ResponseWrapper) AssertStatus

func (r *ResponseWrapper) AssertStatus(expected int) *ResponseWrapper

AssertStatus asserts that the response HTTP status code matches expected.

func (*ResponseWrapper) AssertViolation

func (r *ResponseWrapper) AssertViolation(field, rule string) *ResponseWrapper

AssertViolation verifies that a Problem Details response contains a field violation.

func (*ResponseWrapper) DecodeInto

func (r *ResponseWrapper) DecodeInto(target any) *ResponseWrapper

DecodeInto strictly decodes a response body. Empty 204 responses leave the target unchanged; empty bodies for other statuses fail the test.

func (*ResponseWrapper) Problem

func (r *ResponseWrapper) Problem() gpp.ProblemDetails

Problem decodes and validates an RFC 7807 response body.

type Tester

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

Tester provides simple 3-line E2E API integration testing for goplusplus applications.

func New

func New(t testing.TB, app *gpp.Engine) *Tester

New initializes an API tester for a goplusplus application engine.

func (*Tester) DELETE

func (st *Tester) DELETE(target string) *ResponseWrapper

DELETE performs a simulated DELETE request.

func (*Tester) GET

func (st *Tester) GET(target string) *ResponseWrapper

GET performs a simulated GET request.

func (*Tester) POST

func (st *Tester) POST(target string, body any) *ResponseWrapper

POST performs a simulated POST request with a JSON body.

func (*Tester) PUT

func (st *Tester) PUT(target string, body any) *ResponseWrapper

PUT performs a simulated PUT request with a JSON body.

func (*Tester) Request

func (st *Tester) Request(method, target string, body any, headers map[string]string) *ResponseWrapper

Request performs a simulated HTTP request against the application engine without opening network sockets.

Jump to

Keyboard shortcuts

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