Help us shape the future of Go! Take the 2026 Go Developer Survey

foliotest

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package foliotest drives a folio app (or any http.Handler) in tests, keeping cookies between requests like a browser.

func TestHome(t *testing.T) {
	c := foliotest.New(t, app.Handler())
	c.Get("/").ExpectStatus(200).ExpectContains("Welcome")
	c.PostForm("/", url.Values{"name": {"Ada"}}).ExpectRedirect("/").Follow().ExpectContains("Saved")
}

Index

Constants

View Source
const BaseURL = "http://example.com"

BaseURL is the origin requests are made against.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	// Header is added to every request.
	Header http.Header
	// contains filtered or unexported fields
}

Client sends requests straight to a handler, without a network.

func New

func New(t testing.TB, h http.Handler) *Client

New returns a Client for h.

func (*Client) Cookie

func (c *Client) Cookie(name string) string

Cookie returns the value of a cookie the client holds, or "".

func (*Client) Do

func (c *Client) Do(req *http.Request) *Response

Do sends req with the client's cookies and headers. Redirects aren't followed; see Response.Follow.

func (*Client) Get

func (c *Client) Get(target string) *Response

Get requests target, e.g. "/journal/42?tab=notes".

func (*Client) PostForm

func (c *Client) PostForm(target string, form url.Values) *Response

PostForm submits form values to target as a browser form would.

func (*Client) PostJSON

func (c *Client) PostJSON(target, body string) *Response

PostJSON sends body (already-encoded JSON) to target.

type Response

type Response struct {
	Code   int
	Header http.Header
	Body   string
	// contains filtered or unexported fields
}

Response is a recorded response with chainable assertions.

func (*Response) ExpectContains

func (r *Response) ExpectContains(s string) *Response

ExpectContains fails the test unless the body contains s.

func (*Response) ExpectNotContains

func (r *Response) ExpectNotContains(s string) *Response

ExpectNotContains fails the test if the body contains s.

func (*Response) ExpectRedirect

func (r *Response) ExpectRedirect(location string) *Response

ExpectRedirect fails the test unless the response redirects to location.

func (*Response) ExpectStatus

func (r *Response) ExpectStatus(code int) *Response

ExpectStatus fails the test unless the status is code.

func (*Response) Follow

func (r *Response) Follow() *Response

Follow requests the redirect target.

Jump to

Keyboard shortcuts

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