webtest

package
v11.1.4-modfix Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestWithSignedInUser

func RequestWithSignedInUser(req *http.Request, usr *user.SignedInUser) *http.Request

func RequestWithWebContext

func RequestWithWebContext(req *http.Request, c *contextmodel.ReqContext) *http.Request

Types

type Context

type Context struct {
	Req  *http.Request
	Rw   http.ResponseWriter
	Next http.Handler
}

func MiddlewareContext

func MiddlewareContext(test Middleware, req *http.Request) *Context

MiddlewareContext returns a *http.Request, http.ResponseWriter and http.Handler exactly as if it was passed to a middleware

type Middleware

type Middleware struct {
	// Before are run ahead of the returned context
	Before []web.Handler
	// After are part of the http.Handler chain
	After []web.Handler
	// The actual handler at the end of the chain
	Handler web.Handler
}

Middleware is a utility for testing middlewares

type Server

type Server struct {
	Mux           *web.Mux
	RouteRegister routing.RouteRegister
	TestServer    *httptest.Server
	// contains filtered or unexported fields
}

func NewServer

func NewServer(t testing.TB, routeRegister routing.RouteRegister) *Server

NewServer starts and returns a new server.

func (*Server) NewGetRequest

func (s *Server) NewGetRequest(target string) *http.Request

NewGetRequest creates a new GET request setup for test.

func (*Server) NewPostRequest

func (s *Server) NewPostRequest(target string, body io.Reader) *http.Request

NewPostRequest creates a new POST request setup for test.

func (*Server) NewRequest

func (s *Server) NewRequest(method string, target string, body io.Reader) *http.Request

NewRequest creates a new request setup for test.

func (*Server) Send

func (s *Server) Send(req *http.Request) (*http.Response, error)

Send sends a HTTP request to the test server and returns an HTTP response.

func (*Server) SendJSON

func (s *Server) SendJSON(req *http.Request) (*http.Response, error)

SendJSON sets the Content-Type header to application/json and sends a HTTP request to the test server and returns an HTTP response. Suitable for POST/PUT/PATCH requests that sends request body as JSON.

Jump to

Keyboard shortcuts

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