server

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: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockServer

type MockServer struct {
	Server *httptest.Server
	Header *http.Header
}

func NewMockServer

func NewMockServer(handler http.Handler) *MockServer

Start mock server

func NewMockTLSServer

func NewMockTLSServer(handler http.Handler) *MockServer

Start mock server with TLS mode

func (*MockServer) Close

func (c *MockServer) Close()

close server

func (*MockServer) Cookie

func (c *MockServer) Cookie(cookies []*http.Cookie)

func (*MockServer) Do

func (c *MockServer) Do(t *testing.T, path string, method string, body io.Reader) *Response

func (*MockServer) FormData

func (c *MockServer) FormData(t *testing.T, path string, method string, form *contents.Multipart) *Response

multipart/form-data

func (*MockServer) Get

func (c *MockServer) Get(t *testing.T, path string) *Response

GET Request

func (*MockServer) GetOK

func (c *MockServer) GetOK(t *testing.T, path string) *Response

Get Request and check status 200

func (*MockServer) Post

func (c *MockServer) Post(t *testing.T, path string, contentType string, body io.Reader) *Response

POST Requests

func (*MockServer) PostForm

func (c *MockServer) PostForm(t *testing.T, path string, value url.Values) *Response

application/x-www-form-urlencoded

func (*MockServer) PostFormData

func (c *MockServer) PostFormData(t *testing.T, path string, form *contents.Multipart) *Response

POST multipart/form-data

func (*MockServer) PostJson

func (c *MockServer) PostJson(t *testing.T, path string, obj any) *Response

application/json

func (*MockServer) PostString

func (c *MockServer) PostString(t *testing.T, path string, contentType string, body string) *Response

func (*MockServer) URL

func (c *MockServer) URL(path string) string

convert to mock server url

type Response

type Response struct {
	Resp *http.Response
}

func NewResponse

func NewResponse(resp *http.Response) *Response

func (*Response) Body

func (c *Response) Body() *bytes.Buffer

func (*Response) EqBody

func (c *Response) EqBody(t *testing.T, body string)

func (*Response) EqJson

func (c *Response) EqJson(t *testing.T, obj any)

func (*Response) Json added in v1.1.2

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

Prase json body

func (*Response) Ok

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

func (*Response) SetCookies added in v1.1.2

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

Returns set-cookie's

func (*Response) Status

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

Jump to

Keyboard shortcuts

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