Documentation
¶
Overview ¶
Package webtest provides lightweight test helpers for web handlers and middleware.
Index ¶
- type Context
- func (c *Context) AddHeader(name string, value string)
- func (c *Context) AppSourceName() string
- func (c *Context) Bind(target any) error
- func (c *Context) Blob(code int, contentType string, body []byte) error
- func (c *Context) Context() context.Context
- func (c *Context) Cookie(name string) (*http.Cookie, error)
- func (c *Context) File(path string) error
- func (c *Context) Get(key string) any
- func (c *Context) HTML(code int, body string) error
- func (c *Context) Header(name string) string
- func (c *Context) Host() string
- func (c *Context) JSON(code int, payload any) error
- func (c *Context) Method() string
- func (c *Context) Native() any
- func (c *Context) NoContent(code int) error
- func (c *Context) Param(name string) string
- func (c *Context) Path() string
- func (c *Context) Query(name string) string
- func (c *Context) RawRequest() *http.Request
- func (c *Context) RealIP() string
- func (c *Context) Redirect(code int, url string) error
- func (c *Context) Request() *http.Request
- func (c *Context) Response() web.Response
- func (c *Context) ResponseWriter() http.ResponseWriter
- func (c *Context) Scheme() string
- func (c *Context) Set(key string, value any)
- func (c *Context) SetAppSourceName(source string)
- func (c *Context) SetCookie(cookie *http.Cookie)
- func (c *Context) SetHeader(name string, value string)
- func (c *Context) SetRequest(request *http.Request)
- func (c *Context) SetResponseWriter(writer http.ResponseWriter)
- func (c *Context) StatusCode() int
- func (c *Context) Text(code int, body string) error
- func (c *Context) URI() string
- type PathParams
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a lightweight web.Context implementation for handler tests built on httptest.
func NewContext ¶
func NewContext(request *http.Request, recorder *httptest.ResponseRecorder, path string, pathParams PathParams) *Context
NewContext creates a new test context around the provided request/recorder pair. @group Testing Example: req := httptest.NewRequest(http.MethodGet, "/users/42?expand=roles", nil) ctx := webtest.NewContext(req, nil, "/users/:id", webtest.PathParams{"id": "42"}) fmt.Println(ctx.Param("id"), ctx.Query("expand"))
// 42 roles
func (*Context) AppSourceName ¶
func (*Context) RawRequest ¶
func (*Context) ResponseWriter ¶
func (c *Context) ResponseWriter() http.ResponseWriter
func (*Context) SetAppSourceName ¶
func (*Context) SetRequest ¶
func (*Context) SetResponseWriter ¶
func (c *Context) SetResponseWriter(writer http.ResponseWriter)
func (*Context) StatusCode ¶
type PathParams ¶
PathParams captures named path parameter values for test contexts.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response exposes the recorded response state for a test Context.
func (*Response) SetWriter ¶
func (r *Response) SetWriter(writer http.ResponseWriter)
func (*Response) StatusCode ¶
func (*Response) Writer ¶
func (r *Response) Writer() http.ResponseWriter
Click to show internal directories.
Click to hide internal directories.