test

package
v0.0.0-...-0b96de9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package test implements utilities for testing

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t *testing.T, err error, wantErr string)

AssertError asserts an error by checking if the `Error()` strings are equal

Types

type HandlerPath

type HandlerPath struct {
	Method          string
	Path            string
	Response        string
	ResponseHandler func(http.ResponseWriter, *http.Request)
	ResponseCode    int
}

func (*HandlerPath) HandlerFunc

func (hp *HandlerPath) HandlerFunc() func(http.ResponseWriter, *http.Request)

type HandlerSet

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

HandlerSet is a struct with a mutex that allows us to swap handlers while a test server is running

func (*HandlerSet) ServeHTTP

func (hs *HandlerSet) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves HTTP using the handler

func (*HandlerSet) SetHandler

func (hs *HandlerSet) SetHandler(handler http.Handler)

SetHandler sets the handler to `handler`

type Server

type Server struct {
	*httptest.Server
}

Server wraps a HTTP test server

func NewServer

func NewServer(handler http.Handler, listener net.Listener) *Server

NewServer creates a new test server

func NewServerWithHandles

func NewServerWithHandles(hps []HandlerPath, listener net.Listener) *Server

NewServerWithHandles creates a new test servers with path and responses

func (*Server) Client

func (srv *Server) Client() (*httpw.Client, error)

Client returns a test client that trusts the HTTPS certificates

Jump to

Keyboard shortcuts

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