drivertest

package
v1.10.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: 6 Imported by: 0

Documentation

Overview

Package drivertest provides shared HTTP mock-server helpers for driver unit tests. It is intentionally stdlib-only so opt-in driver modules can import it without adding dependencies.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CapturedRequest

type CapturedRequest struct {
	Method string
	Path   string
	Query  string
	Header http.Header
	Body   []byte
}

CapturedRequest holds the details of the last request the mock server saw.

func (*CapturedRequest) DecodeJSON

func (c *CapturedRequest) DecodeJSON(t *testing.T, v any)

DecodeJSON unmarshals the captured body into v, failing the test on error.

func (*CapturedRequest) FormValue

func (c *CapturedRequest) FormValue(t *testing.T, key string) string

FormValue parses the captured body as a URL-encoded form and returns key.

type Server

type Server struct {
	*httptest.Server
	Captured *CapturedRequest
}

Server wraps an httptest.Server that records the request it received and replies with a fixed status code and body.

func NewServer

func NewServer(t *testing.T, status int, respBody string) *Server

NewServer starts a mock HTTP server. Every request is recorded into Captured; the server replies with status and respBody. extraHeaders set on the response can be added by the caller via the returned server if needed.

Jump to

Keyboard shortcuts

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