ktest

package
v0.0.0-...-5f133c6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CacheTime = time.Unix(10, 0)

Functions

func CachableHelloHandler

func CachableHelloHandler(w http.ResponseWriter, r *http.Request)

Always returns the string "hello", with headers that allow caching.

func ErrorHandler

func ErrorHandler(w http.ResponseWriter, r *http.Request)

ErrorHandler returns a StatusInternalServerError.

func HangingHandler

func HangingHandler(w http.ResponseWriter, r *http.Request)

HangingHandler hangs forever.

func HelloHandler

func HelloHandler(w http.ResponseWriter, r *http.Request)

Always returns the string "hello".

func Start

func Start(s http.Handler) (string, error)

Start is just like StartURL, but returns a string instead of an URL object.

func StartServer

func StartServer(h Handler) (*http.ServeMux, string, error)

StartServer is just like Start, excepts it creates and returns a new mux.

func StartServerURL

func StartServerURL(h Handler) (*http.ServeMux, *url.URL, error)

StartServerURL is like StartURL, except it creates and returns a new mux.

func StartURL

func StartURL(s http.Handler) (*url.URL, error)

StartURL starts an http server listening on a random port.

Uses the supplied http.Handler to serve pages, returns the full URL it is listening on.

func TimeoutHandler

func TimeoutHandler(w http.ResponseWriter, r *http.Request)

Types

type Handler

type Handler func(w http.ResponseWriter, r *http.Request)

func CachableFileHandler

func CachableFileHandler(file string) Handler

Returns a file, cachable.

func CachableStringHandler

func CachableStringHandler(message string) Handler

CachableStringHandler reeturns a string, adding headers that allow client caching.

func CachableTestDataHandler

func CachableTestDataHandler(file string) Handler

Returns a file from the "testdata" directory", cachable.

func FileHandler

func FileHandler(file string) Handler

Returns a file not cachable.

func Slow

func Slow(d time.Duration, h Handler) Handler

Slow will slow down the responses by the specified amount. Convenient to try to trigger timeouts, or race conditions.

func StringHandler

func StringHandler(message string) Handler

StringHandler just reeturns a string, WITHOUT any header that allows caching.

func TestDataHandler

func TestDataHandler(file string) Handler

Returns a file from the "testdata" directory", not cachable.

type Recorder

type Recorder struct {
	Handler  Handler
	Request  []*http.Request
	Response []*http.Response
}

func Capture

func Capture(handler Handler) *Recorder

func (*Recorder) Handle

func (capture *Recorder) Handle(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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