testserver

package
v0.0.0-...-5ee2aa8 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testserver provides a one-line setup for HTTP-handler tests. New(t) returns an httptest.Server backed by in-memory fakes. Tests inspect the embedded Stores to verify side effects.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(t *testing.T, resp *http.Response, out any)

DecodeJSON reads the response body and unmarshals into out.

func ReadBody

func ReadBody(t *testing.T, resp *http.Response) string

ReadBody reads the response body as a string.

Types

type TS

type TS struct {
	*httptest.Server
	Stores    *fakes.Stores
	Encryptor *crypto.Encryptor
	DataDir   string
}

TS bundles a running httptest.Server with the in-memory fakes that back it.

func New

func New(t *testing.T) *TS

New returns a fully-wired test server backed by in-memory fakes. Auth is disabled (empty Google client ID/secret).

func (*TS) Delete

func (ts *TS) Delete(t *testing.T, path string) *http.Response

Delete issues a DELETE.

func (*TS) Get

func (ts *TS) Get(t *testing.T, path string) *http.Response

Get issues a GET against the test server.

func (*TS) Post

func (ts *TS) Post(t *testing.T, path string, body any) *http.Response

Post issues a POST with a JSON body.

func (*TS) Put

func (ts *TS) Put(t *testing.T, path string, body any) *http.Response

Put issues a PUT with a JSON body.

Jump to

Keyboard shortcuts

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