mockutils

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2024 License: MIT Imports: 4 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(t *testing.T, requests []Request) http.HandlerFunc

Handler is used with a [httptest.Server] to mock http requests provided by the user.

Request matching is based on the request count, and the user provided request will be iterated over.

Types

type Request

type Request struct {
	Method string
	Path   string
	Want   func(t *testing.T, r *http.Request)

	Status  int
	JSON    any
	JSONRaw string
}

Request describes a http request that a [httptest.Server] should receive, and the corresponding response to return.

Additional checks on the request (e.g. request body) may be added using the Request.Want function.

The response body is populated from either a JSON struct, or a JSON string.

Jump to

Keyboard shortcuts

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