Documentation
¶
Overview ¶
Package testutils contains candidates to be moved to go-common/testutils
Package testutils provides various unit test utilities.
Deprecated: moved to codeberg.org/clambin/go-common
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Eventually ¶ added in v0.3.0
Types ¶
type Path ¶ added in v0.2.0
type Path struct {
// Methods defines which HTTP methods should be accepted. If the request doesn't match, TestServer returns HTTP 405.
// If Methods is empty, all HTTP methods are accepted.
Methods []string
// StatusCode tells TestServer what HTTP status code to return for matching requests.
// If StatusCode is 0, TestServer returns HTTP 200.
StatusCode int
// Body is the body that TestServer will return for the Path. If Body is a string, or a []byte, it is sent as is.
// Otherwise, it is marshalled as a JSON object.
Body any
}
Path defines how TestServer should reply to a request.
type TestServer ¶ added in v0.2.0
TestServer is a dummy http.Handler that can be used to create a httptest.Server. TestServer serves HTTP requests, using Path to determine how to reply, by looking up r.URL.Path in Paths. If no Path matches the request, TestServer returns HTTP 404
func (*TestServer) Calls ¶ added in v0.2.0
func (t *TestServer) Calls() map[string]int
Calls returns how many requests were accepted for each path.
func (*TestServer) ServeHTTP ¶ added in v0.2.0
func (t *TestServer) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*TestServer) TotalCalls ¶ added in v0.2.0
func (t *TestServer) TotalCalls() int
TotalCalls returns how many requests were accepted for all paths.
Click to show internal directories.
Click to hide internal directories.