mock

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: MIT Imports: 12 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) 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) Ok

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

Check if request success

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