Documentation ¶
Overview ¶
A helper utilities for testing `http.HandlerFunc`
Index ¶
- type Expectation
- func Delete(t TestingT, handler http.HandlerFunc) *Expectation
- func Get(t TestingT, handler http.HandlerFunc) *Expectation
- func Head(t TestingT, handler http.HandlerFunc) *Expectation
- func Patch(t TestingT, handler http.HandlerFunc) *Expectation
- func Post(t TestingT, handler http.HandlerFunc) *Expectation
- func Put(t TestingT, handler http.HandlerFunc) *Expectation
- func (e *Expectation) Header(key string) *JSONArray
- func (e *Expectation) JSONArray() *JSONArray
- func (e *Expectation) JSONObject() *JSONObject
- func (e *Expectation) NoContent() *Expectation
- func (e *Expectation) Require() *Expectation
- func (e *Expectation) Status(status int) *Expectation
- func (e *Expectation) WithContext(ctx context.Context) *Expectation
- func (e *Expectation) WithExtraHeader(key, value string) *Expectation
- func (e *Expectation) WithJSON(data any) *Expectation
- func (e *Expectation) WithMiddlewares(middlewares ...func(http.Handler) http.Handler) *Expectation
- func (e *Expectation) WithPlainText(data []byte) *Expectation
- func (e *Expectation) WithQuery(query string) *Expectation
- func (e *Expectation) WithoutBody() *Expectation
- type JSONArray
- func (a *JSONArray) Array(idx int) *JSONArray
- func (a *JSONArray) Bool(idx int) *JSONBool
- func (a *JSONArray) Len() *JSONNumber
- func (a *JSONArray) Null(idx int)
- func (a *JSONArray) Number(idx int) *JSONNumber
- func (a *JSONArray) Object(idx int) *JSONObject
- func (a *JSONArray) String(idx int) *JSONString
- type JSONArrayType
- type JSONBool
- type JSONNumber
- type JSONObject
- func (o *JSONObject) Array(key string) *JSONArray
- func (o *JSONObject) Bool(key string) *JSONBool
- func (o *JSONObject) HasKey(key string) *JSONObject
- func (o *JSONObject) Null(key string)
- func (o *JSONObject) Number(key string) *JSONNumber
- func (o *JSONObject) Object(key string) *JSONObject
- func (o *JSONObject) String(key string) *JSONString
- type JSONObjectType
- type JSONString
- type TestingT
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expectation ¶
type Expectation struct {
// contains filtered or unexported fields
}
func Delete ¶
func Delete(t TestingT, handler http.HandlerFunc) *Expectation
func Get ¶
func Get(t TestingT, handler http.HandlerFunc) *Expectation
Example ¶
stubHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte(`{"bool": true, "number": 1337, "string": "str", "object": {}, "array": []}`)) }) t := &testing.T{} Get(t, stubHandler).Status(http.StatusOK).JSONObject().Bool("bool").True()
Output:
func Head ¶
func Head(t TestingT, handler http.HandlerFunc) *Expectation
func Patch ¶
func Patch(t TestingT, handler http.HandlerFunc) *Expectation
func Post ¶
func Post(t TestingT, handler http.HandlerFunc) *Expectation
func Put ¶
func Put(t TestingT, handler http.HandlerFunc) *Expectation
func (*Expectation) Header ¶
func (e *Expectation) Header(key string) *JSONArray
func (*Expectation) JSONArray ¶
func (e *Expectation) JSONArray() *JSONArray
func (*Expectation) JSONObject ¶
func (e *Expectation) JSONObject() *JSONObject
func (*Expectation) NoContent ¶
func (e *Expectation) NoContent() *Expectation
func (*Expectation) Require ¶
func (e *Expectation) Require() *Expectation
func (*Expectation) Status ¶
func (e *Expectation) Status(status int) *Expectation
func (*Expectation) WithContext ¶
func (e *Expectation) WithContext(ctx context.Context) *Expectation
func (*Expectation) WithExtraHeader ¶
func (e *Expectation) WithExtraHeader(key, value string) *Expectation
func (*Expectation) WithJSON ¶
func (e *Expectation) WithJSON(data any) *Expectation
func (*Expectation) WithMiddlewares ¶
func (e *Expectation) WithMiddlewares(middlewares ...func(http.Handler) http.Handler) *Expectation
func (*Expectation) WithPlainText ¶
func (e *Expectation) WithPlainText(data []byte) *Expectation
func (*Expectation) WithQuery ¶
func (e *Expectation) WithQuery(query string) *Expectation
func (*Expectation) WithoutBody ¶
func (e *Expectation) WithoutBody() *Expectation
type JSONArray ¶
type JSONArray struct {
// contains filtered or unexported fields
}
func (*JSONArray) Len ¶
func (a *JSONArray) Len() *JSONNumber
func (*JSONArray) Number ¶
func (a *JSONArray) Number(idx int) *JSONNumber
func (*JSONArray) Object ¶
func (a *JSONArray) Object(idx int) *JSONObject
func (*JSONArray) String ¶
func (a *JSONArray) String(idx int) *JSONString
type JSONArrayType ¶
type JSONArrayType = []interface{}
type JSONNumber ¶
type JSONNumber struct {
// contains filtered or unexported fields
}
func (*JSONNumber) Equal ¶
func (n *JSONNumber) Equal(value float64)
func (*JSONNumber) EqualDelta ¶
func (n *JSONNumber) EqualDelta(value, delta float64)
func (*JSONNumber) Value ¶
func (n *JSONNumber) Value() float64
type JSONObject ¶
type JSONObject struct {
// contains filtered or unexported fields
}
func (*JSONObject) Array ¶
func (o *JSONObject) Array(key string) *JSONArray
func (*JSONObject) Bool ¶
func (o *JSONObject) Bool(key string) *JSONBool
func (*JSONObject) HasKey ¶
func (o *JSONObject) HasKey(key string) *JSONObject
func (*JSONObject) Null ¶
func (o *JSONObject) Null(key string)
func (*JSONObject) Number ¶
func (o *JSONObject) Number(key string) *JSONNumber
func (*JSONObject) Object ¶
func (o *JSONObject) Object(key string) *JSONObject
func (*JSONObject) String ¶
func (o *JSONObject) String(key string) *JSONString
type JSONObjectType ¶
type JSONObjectType = map[string]interface{}
type JSONString ¶
type JSONString struct {
// contains filtered or unexported fields
}
func (*JSONString) Equal ¶
func (s *JSONString) Equal(value string)
func (*JSONString) HasPrefix ¶
func (s *JSONString) HasPrefix(prefix string)
func (*JSONString) HasSuffix ¶
func (s *JSONString) HasSuffix(suffix string)
func (*JSONString) Len ¶
func (s *JSONString) Len() *JSONNumber
func (*JSONString) Value ¶
func (s *JSONString) Value() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.