mockServer

package
v0.0.0-...-d1b91f6 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const InternalServerError string = "500 Internal Server Error"

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPcode

type HTTPcode uint16

type HTTPerror

type HTTPerror struct {
	Message string
	Code    HTTPcode
}

func JsonError

func JsonError(code HTTPcode, data map[string]any) HTTPerror

type Method

type Method string
const (
	DELETE Method = "DELETE"
	GET    Method = "GET"
	POST   Method = "POST"
	PUT    Method = "PUT"
)

func (Method) String

func (m Method) String() string

type Path

type Path string

func (Path) String

func (p Path) String() string

type Request

type Request struct {
	Method      Method
	Path        Path
	HandlerFunc func(w http.ResponseWriter, r *http.Request, t *testing.T)
}

func Append

func Append(r ...[]Request) []Request

func RequestsAuth

func RequestsAuth() []Request

func RequestsDelete

func RequestsDelete(urlPath Path, expected any) []Request

func RequestsDeleteResponse

func RequestsDeleteResponse(urlPath Path, expected any, response []byte) []Request

func RequestsError

func RequestsError(url Path, method Method, Code HTTPcode, amount uint) []Request

func RequestsErrorHandled

func RequestsErrorHandled(url Path, method Method, err HTTPerror) []Request

func RequestsGetJson

func RequestsGetJson(urlPath Path, v any) []Request

func RequestsPost

func RequestsPost(urlPath Path, expected any) []Request

RequestsPost creates a request that expects a POST with JSON body matching 'expected' all values in 'expected' will be treated as strings or arrays of strings.

func RequestsPostResponse

func RequestsPostResponse(urlPath Path, expected any, response []byte) []Request

func RequestsPut

func RequestsPut(urlPath Path, expected any) []Request

RequestsPut creates a request that expects a PUT with JSON body matching 'expected' all values in 'expected' will be treated as strings or arrays of strings.

func RequestsPutHandler

func RequestsPutHandler(urlPath Path, handler func(t *testing.T, v url.Values)) []Request

func RequestsVersion

func RequestsVersion(version string) []Request

type Server

type Server struct {
	// contains filtered or unexported fields
}

func New

func New(t *testing.T) *Server

func (*Server) Clear

func (s *Server) Clear(t *testing.T)

Clear removes all configured requests and responses. Panics if there are unhandled requests remaining.

func (*Server) Set

func (s *Server) Set(request []Request, t *testing.T)

func (*Server) Url

func (s *Server) Url() string

Jump to

Keyboard shortcuts

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