mock

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

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

func NewFormData(path string, data *contents.Multipart, method string) (*MockHandler, error)

multipart/form-data type. Use the POST or PUT method.

func NewGet

func NewGet(body string, path string) (*MockHandler, error)

GET Requests

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

func NewMockReader(body io.Reader, method string, path string) (*MockHandler, error)

Create mock objects use io.Reader body. if set path is empty, replace to /.

Example:

m, err := NewMockReader(strings.NewReader(""), http.MethodGet, "/")

func NewURLEncoded

func NewURLEncoded(path string, data url.Values, method string) (*MockHandler, error)

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 added in v1.1.1

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) Handler

func (c *MockHandler) Handler(hand func(w http.ResponseWriter, r *http.Request))

Add handler

func (*MockHandler) Json added in v1.1.2

func (c *MockHandler) Json(v any) error

Prase json body

func (*MockHandler) Ok

func (c *MockHandler) Ok(t *testing.T)

Check if request success

func (*MockHandler) Response added in v1.1.2

func (c *MockHandler) Response() *http.Response

Returns response

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 added in v1.1.2

func (c *MockHandler) SetCookies() []*http.Cookie

Returns Set-Cookie headers

func (*MockHandler) Status

func (c *MockHandler) Status(t *testing.T, status int)

Check response status code

Jump to

Keyboard shortcuts

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