Documentation ¶
Index ¶
- type MockHandler
- func NewFormData(path string, method string, data *Multipart) (*MockHandler, error)
- func NewJson(path string, method string, data any) (*MockHandler, error)
- func NewMock(path string, method string, body string) (*MockHandler, error)
- func NewMockReader(path string, method string, body io.Reader) (*MockHandler, error)
- func NewURLEncoded(path string, method string, data url.Values) (*MockHandler, error)
- func (c *MockHandler) Cookie(cookies []*http.Cookie)
- func (c *MockHandler) Echo() echo.Context
- func (c *MockHandler) EqBody(t *testing.T, body string)
- func (c *MockHandler) EqJson(t *testing.T, obj any)
- func (c *MockHandler) FindCookie(name string) *http.Cookie
- func (c *MockHandler) Handler(hand func(w http.ResponseWriter, r *http.Request))
- func (c *MockHandler) Json(v any) error
- func (c *MockHandler) Ok(t *testing.T)
- func (c *MockHandler) Response() *http.Response
- func (c *MockHandler) SetAddr(addr string)
- func (c *MockHandler) SetCookies() []*http.Cookie
- func (c *MockHandler) Status(t *testing.T, status int)
- type MockServer
- func (c *MockServer) Close()
- func (c *MockServer) Cookie(cookies []*http.Cookie)
- func (c *MockServer) Do(t *testing.T, path string, method string, body io.Reader) *Response
- func (c *MockServer) FormData(t *testing.T, path string, method string, form *Multipart) *Response
- func (c *MockServer) Get(t *testing.T, path string) *Response
- func (c *MockServer) GetOK(t *testing.T, path string) *Response
- func (c *MockServer) Post(t *testing.T, path string, contentType string, body io.Reader) *Response
- func (c *MockServer) PostForm(t *testing.T, path string, value url.Values) *Response
- func (c *MockServer) PostFormData(t *testing.T, path string, form *Multipart) *Response
- func (c *MockServer) PostJson(t *testing.T, path string, obj any) *Response
- func (c *MockServer) PostString(t *testing.T, path string, contentType string, body string) *Response
- func (c *MockServer) URL(path string) string
- type Multipart
- type Response
- func (c *Response) Body() *bytes.Buffer
- func (c *Response) EqBody(t *testing.T, body string)
- func (c *Response) EqJson(t *testing.T, obj any)
- func (c *Response) Json(v any) error
- func (c *Response) Ok(t *testing.T)
- func (c *Response) SetCookies() []*http.Cookie
- func (c *Response) Status(t *testing.T, status int)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockHandler ¶
type MockHandler struct { W *httptest.ResponseRecorder R *http.Request Cookies []string }
func NewFormData ¶
func NewFormData(path string, method string, data *Multipart) (*MockHandler, error)
multipart/form-data type. Use the POST or PUT method.
func NewJson ¶
func NewJson(path string, method string, data any) (*MockHandler, error)
Post json. Use the POST or PUT method.
func NewMock ¶
func NewMock(path string, method string, body string) (*MockHandler, error)
Create mock objects. if set path is empty, replace to /.
Example:
m, err := NewMock("", http.MethodGet, "/")
func NewMockReader ¶
Create mock objects use io.Reader body. if set path is empty, replace to /.
Example:
m, err := NewMockReader(strings.NewReader(""), http.MethodGet, "/")
func NewURLEncoded ¶
application/x-www-form-urlencoded type. Use the POST or PUT method.
func (*MockHandler) Cookie ¶
func (c *MockHandler) Cookie(cookies []*http.Cookie)
Including cookies in the request
func (*MockHandler) Echo ¶
func (c *MockHandler) Echo() echo.Context
Returns echo context this method is require labstack/echo package.
Usage:
c := m.Echo() c.SetPath("/users/:email") c.SetParamNames("email") c.SetParamValues("jon@labstack.com")
func (*MockHandler) EqBody ¶
func (c *MockHandler) EqBody(t *testing.T, body string)
Compare response body
func (*MockHandler) EqJson ¶
func (c *MockHandler) EqJson(t *testing.T, obj any)
Compare response body written json
func (*MockHandler) FindCookie ¶
func (c *MockHandler) FindCookie(name string) *http.Cookie
Returns set-cookie
func (*MockHandler) Handler ¶
func (c *MockHandler) Handler(hand func(w http.ResponseWriter, r *http.Request))
Add handler
func (*MockHandler) SetAddr ¶
func (c *MockHandler) SetAddr(addr string)
Set RemoteAddr
default to 192.0.2.1:1234 is "TEST-NET" in RFC 5737
func (*MockHandler) SetCookies ¶
func (c *MockHandler) SetCookies() []*http.Cookie
Returns Set-Cookie headers
type MockServer ¶
func NewMockTLSServer ¶
func NewMockTLSServer(handler http.Handler) *MockServer
Start mock server with TLS mode
func (*MockServer) Cookie ¶
func (c *MockServer) Cookie(cookies []*http.Cookie)
func (*MockServer) GetOK ¶
func (c *MockServer) GetOK(t *testing.T, path string) *Response
Get Request and check status 200
func (*MockServer) PostFormData ¶
POST multipart/form-data
func (*MockServer) PostString ¶
type Multipart ¶
type Multipart struct {
// contains filtered or unexported fields
}
func NewMultipart ¶
func NewMultipart() *Multipart
Create a new multipart/form-data object
Example:
m := NewMultipart() // Insert k-v data err := m.Insert("key", "value") require.NoError(t, err) // Insert files err := m.InsertFile("key", file)
func (*Multipart) ContentType ¶
Outputs content-type