testutils

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: MIT Imports: 5 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSONLogger

func NewJSONLogger(output io.Writer, level slog.Level) *slog.Logger

func NewTextLogger

func NewTextLogger(output io.Writer, level slog.Level) *slog.Logger

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.
	Body []byte
}

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, where the key is matched again r.URL.Path. 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