test

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(method, target string, body io.Reader) *http.Request

NewRequest creates a new HTTP request. It's a wrapper around httptest.NewRequest but handy for consistency.

func SetPathValue

func SetPathValue(req *http.Request, key, value string)

SetPathValue sets a path value on the request. This is useful for testing handlers that rely on path parameters (c.Param). Note: This requires Go 1.22+.

func TemplateFromString

func TemplateFromString(templates map[string]string) *template.Template

TemplateFromString creates a *template.Template from a string map. Keys are template names (e.g. "index.html") and values are the content. Useful for quick tests without creating files.

func Test

func Test(r *rex.Router, req *http.Request) (*http.Response, error)

Test executes the request against the router and returns the response. It mimics the behavior of the real server by using the router's ServeHTTP method.

func TestHandler

func TestHandler(h rex.HandlerFunc, req *http.Request, options ...rex.RouterOption) (*http.Response, error)

TestHandler executes a specific handler in isolation with a temporary router context. It allows testing handlers that require router features like templates without registering a route.

If the handler returns an error, it is returned directly. The response in the recorder contains whatever was written to the ResponseWriter up to that point.

Example:

func TestMyHandler(t *testing.T) {
    req := httptest.NewRequest("GET", "/", nil)
    resp, err := test.TestHandler(MyHandler, req, rex.WithTemplates(tmpl))
    // ...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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