testutils

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: MIT Imports: 7 Imported by: 0

README

testutils

release codecov test go report card godoc license

Testing utilities

Authors

  • Christophe Lambin

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

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

func Eventually(f func() bool, timeout time.Duration, interval time.Duration) bool

func Panics added in v0.3.0

func Panics(f func()) bool

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

type TestServer struct {
	Paths map[string]Path
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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