httptestx

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

func New

func New(t testing.TB, baseURL string, opts ...Option) *Client

func NewHandler

func NewHandler(t testing.TB, h http.Handler, opts ...Option) *Client

NewHandler returns a client that calls h in-process (no network).

func (*Client) Delete

func (c *Client) Delete[T any](path string, opts ...RequestOption) *Response[T]

func (*Client) Do

func (c *Client) Do[T any](method, path string, in any, opts ...RequestOption) *Response[T]

func (*Client) Get

func (c *Client) Get[T any](path string, opts ...RequestOption) *Response[T]

func (*Client) Patch

func (c *Client) Patch[T any](path string, in any, opts ...RequestOption) *Response[T]

func (*Client) Post

func (c *Client) Post[T any](path string, in any, opts ...RequestOption) *Response[T]

func (*Client) Put

func (c *Client) Put[T any](path string, in any, opts ...RequestOption) *Response[T]

func (*Client) WithT

func (c *Client) WithT(t testing.TB) *Client

type Option

type Option func(*Client)

func WithDefaultHeaders

func WithDefaultHeaders(h map[string]string) Option

func WithHandler

func WithHandler(h http.Handler, remoteAddr string) Option

func WithTimeout

func WithTimeout(d time.Duration) Option

func WithTransport

func WithTransport(rt http.RoundTripper) Option

type RequestOption

type RequestOption func(*http.Request)

func WithBearer

func WithBearer(token string) RequestOption

func WithContext

func WithContext(ctx context.Context) RequestOption

func WithHeader

func WithHeader(k, v string) RequestOption

func WithQuery

func WithQuery(q url.Values) RequestOption

func WithQueryParam

func WithQueryParam(k, v string) RequestOption

type Response

type Response[T any] struct {
	StatusCode int
	Header     http.Header
	Body       T
	RawBody    []byte
}

func (*Response[T]) Assert

func (r *Response[T]) Assert(t testing.TB, wantStatusCode int, wantBody T)

Jump to

Keyboard shortcuts

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