apptest

package
v0.0.0-...-f474cdf Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 12 Imported by: 0 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

Overview

Package apptest is the HTTP harness of the tests of arkoren.dev/ark/access: a router with session and auth middleware behind an in-process server and a client that keeps cookies, like a browser. It imports core only (no driver), and only test files import it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSON

func JSON[T any](t *testing.T, reply Reply) T

JSON decodes the body into a T and fails the test when it is not JSON.

Types

type Client

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

Client is a cookie-keeping HTTP client of one test server.

func Serve

func Serve(t *testing.T, store *cache.Cache, authenticators []auth.Authenticator, mount func(r *router.Router)) *Client

Serve starts a server whose router runs the session middleware over store and the auth middleware over authenticators, then calls mount to register the routes. The server stops with the test.

func ServeRouter

func ServeRouter(t *testing.T, r *router.Router) *Client

ServeRouter starts a server for r, which must already run its own session middleware, and returns a cookie-keeping client. The server stops with the test.

func (*Client) Do

func (client *Client) Do(method, path, body string, headers ...string) Reply

Do sends method path with body (empty for none) and optional "Name: value" headers, and returns the reply. Redirects are not followed.

func (*Client) NewDevice

func (client *Client) NewDevice() *Client

NewDevice returns a client of the same server with its own, empty cookie jar: another browser or phone.

func (*Client) Post

func (client *Client) Post(path, body string) Reply

Post sends a POST with a JSON body.

type Reply

type Reply struct {
	// Status is the HTTP status code.
	Status int

	// Body is the response body.
	Body string

	// Header holds the response headers.
	Header http.Header
}

Reply is one completed response with its body read.

Jump to

Keyboard shortcuts

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