echotest

package
v0.1.92 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package echotest builds echo contexts for handler unit tests so each test states only what differs: method, target, body, and the occasional header or path value.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode[T any](t testing.TB, rec *httptest.ResponseRecorder) T

Decode unmarshals the recorded JSON response body into T, failing the test when it is not valid JSON for T.

func Get

func Get(t testing.TB, target string, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)

Get is Request for a GET with no body.

func Post

func Post(t testing.TB, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)

Post is Request for a POST with a JSON body.

func Request

func Request(t testing.TB, method, target string, body any, opts ...Option) (*echo.Context, *httptest.ResponseRecorder)

Request builds an echo context and recorder for a handler call.

body may be nil (no body), a string or []byte (sent verbatim), an io.Reader, or any other value, which is JSON-encoded. A non-nil body gets a JSON Content-Type unless WithContentType overrides it.

Types

type Option

type Option func(*settings)

Option adjusts the request or context built by Request.

func WithContentType

func WithContentType(contentType string) Option

WithContentType overrides the Content-Type set for a non-nil body.

func WithHeader

func WithHeader(key, value string) Option

WithHeader sets a request header.

func WithPath

func WithPath(path string) Option

WithPath sets the route path template (c.Path), for handlers that inspect it.

func WithPathValue

func WithPathValue(name, value string) Option

WithPathValue binds a route parameter (c.Param) for the handler.

func WithValue

func WithValue(key string, value any) Option

WithValue stores a context value (c.Set) before the handler runs, for values middleware would normally provide.

Jump to

Keyboard shortcuts

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