httptestx

package
v1.14.4 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultToken = "privatisation"
	RefreshToken = "privaterefresh"
)

Variables

This section is empty.

Functions

func CompressHandler

func CompressHandler(h http.Handler) http.Handler

CompressHandler only using for testing, mod from gorilla/handlers/CompressHandler.

func JSONOut

func JSONOut(w http.ResponseWriter, out interface{})

JSONOut using to encode payload as json format.

func MockAuthServer

func MockAuthServer(opts ...MockServerRouterOption) (server *httptest.Server, closer func())

MockAuthServer creates new test http server with listening port 52345.

func ResponseSnapshotMiddleware

func ResponseSnapshotMiddleware(snapshots *[]*ResponseSnapshot) mux.MiddlewareFunc

ResponseSnapshotMiddleware will snapshotting handlers response and append to give snapshots slice.

Types

type MockServerRouterOption

type MockServerRouterOption func(r *mux.Router, ctx *sync.Map) error

MockServerRouterOption used to customized http routers, you can use this type to register your handlers on mock serer.

The second argument called ctx is server provided global state key-value cache, you can use this cache to store customized variables in multiple requests.

func WithBuiltinTestDataEndpoints

func WithBuiltinTestDataEndpoints() MockServerRouterOption

WithBuiltinTestDataEndpoints creates simple data endpoints and register to router.

type ResponseSnapshot

type ResponseSnapshot struct {
	Body    *bytes.Buffer
	Code    int
	Headers http.Header
	Method  string
}

ResponseSnapshot is snapshots for handler response.

Jump to

Keyboard shortcuts

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