apitest

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package apitest drives the API in handler tests the way a same-origin browser would.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

Decode unmarshals the response body into T.

func ErrorOf

func ErrorOf(t *testing.T, rec *httptest.ResponseRecorder) web.APIError

ErrorOf decodes the JSON error envelope.

func NewEcho

func NewEcho() *echo.Echo

NewEcho returns an Echo set up like production: API errors are JSON and other errors get the HTML error page.

Types

type Client

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

Client sends requests to an Echo instance, optionally with a session cookie.

func New

func New(e *echo.Echo) *Client

func (*Client) As

func (c *Client) As(cookie *http.Cookie) *Client

As returns a client that sends cookie with every request.

func (*Client) Do

Do serves req as a same-origin browser request.

func (*Client) Get

func (c *Client) Get(t *testing.T, path string) *httptest.ResponseRecorder

func (*Client) JSON

func (c *Client) JSON(t *testing.T, method, path string, body any) *httptest.ResponseRecorder

JSON sends body encoded as JSON; a nil body sends no body.

func (*Client) Multipart

func (c *Client) Multipart(t *testing.T, method, path string, fields map[string]string, files ...FilePart) *httptest.ResponseRecorder

Multipart sends fields and files as multipart/form-data.

type FilePart

type FilePart struct {
	Field, Name, ContentType, Body string
}

FilePart is one file in a multipart request.

Jump to

Keyboard shortcuts

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