Documentation
¶
Index ¶
- type MockHandler
- func NewFormData(path string, data *contents.Multipart, method string) (*MockHandler, error)
- func NewGet(body string, path string) (*MockHandler, error)
- func NewJson(path string, data any, method string) (*MockHandler, error)
- func NewMock(body string, method string, path string) (*MockHandler, error)
- func NewMockReader(body io.Reader, method string, path string) (*MockHandler, error)
- func NewURLEncoded(path string, data url.Values, method string) (*MockHandler, error)
- func (c *MockHandler) Cookie(cookies []*http.Cookie)
- func (c *MockHandler) EqBody(t *testing.T, body string)
- func (c *MockHandler) EqJson(t *testing.T, obj any)
- func (c *MockHandler) Handler(hand func(w http.ResponseWriter, r *http.Request))
- func (c *MockHandler) Ok(t *testing.T)
- func (c *MockHandler) SetAddr(addr string)
- func (c *MockHandler) 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
}
func NewFormData ¶
multipart/form-data type. Use the POST or PUT method.
func NewJson ¶
func NewJson(path string, data any, method string) (*MockHandler, error)
Post json. Use the POST or PUT method.
func NewMock ¶
func NewMock(body string, method string, path 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) 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) 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
Click to show internal directories.
Click to hide internal directories.