chttptest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package chttptest provides utility functions that are useful when testing chttp

Index

Constants

View Source
const ContentTypeApplicationJSON = "application/json"

ContentTypeApplicationJSON defines the application/json content type that can be used when making HTTP requests.

Variables

This section is empty.

Functions

func NewReaderWriter

func NewReaderWriter(t *testing.T) *chttp.ReaderWriter

NewReaderWriter creates a *chttp.ReaderWriter suitable for use in tests

func NewRouter

func NewRouter(routes []chttp.Route) chttp.Router

NewRouter returns a router that returns the given routes.

func PingRoutes

func PingRoutes(t *testing.T, routes []chttp.Route)

PingRoutes creates a handler using chttp.NewHandler, starts a test http server, and calls each provided route. It verifies that each route's handler is called successfully.

func ReverseRoutes

func ReverseRoutes(routes []chttp.Route) []chttp.Route

ReverseRoutes reverses the provided slice of chttp.Route.

Types

type Middleware

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

Middleware is a simple implementation of chttp.Middleware useful for testing that simply runs the provided func.

func NewMiddleware

func NewMiddleware(fn func(next http.Handler) http.Handler) *Middleware

NewMiddleware returns an implementation of chttp.Middleware that runs the provided func.

func (*Middleware) Handle

func (mw *Middleware) Handle(next http.Handler) http.Handler

Handle runs the provided func and returns its result.

Jump to

Keyboard shortcuts

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