Documentation
¶
Overview ¶
Package test provides multiple tools to write tests faster and keep them simple.
Index ¶
- func PaginatedEndpointTester(t *testing.T, baseRequest RequestTester, pageQueryParamName string, ...)
- type CaseResponse
- type ContentType
- type MatrixTester
- type ParallelOperation
- type RequestTester
- func (tReq *RequestTester) AddCookie(cookie *http.Cookie)
- func (tReq RequestTester) Copy() RequestTester
- func (tReq *RequestTester) Do(t *testing.T) *http.Response
- func (tReq *RequestTester) SetContentType(contentType ContentType)
- func (tReq *RequestTester) SetData(data any)
- func (tReq *RequestTester) SetFollowRedirect(follow bool)
- func (tReq *RequestTester) SetQuery(query url.Values)
- func (tReq *RequestTester) SetTestServer(ts *httptest.Server)
- type WebSocketTester
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PaginatedEndpointTester ¶
func PaginatedEndpointTester( t *testing.T, baseRequest RequestTester, pageQueryParamName string, maxPage int, )
PaginatedEndpointTester uses a predefined configuration for a MatrixTester to test boundaries of a paginated HTTP endpoint.
Types ¶
type CaseResponse ¶
type CaseResponse struct {
// contains filtered or unexported fields
}
CaseResponse is used to compare to the actual response of a RequestTester when used by a MatrixTester.
func NewCaseResponse ¶
func NewCaseResponse(statusCode int, cookies []*http.Cookie, body any) CaseResponse
NewCaseResponse returns a new CaseResponse.
type ContentType ¶
type ContentType = string
ContentType is used to set the "Content-Type" header of requests. This also has an influence on the encoding of your data.
const ( // JSONContentType sets the "Content-Type" header to "application/json". JSONContentType ContentType = "application/json" // FormContentType sets the "Content-Type" header to // "application/x-www-form-urlencoded". FormContentType = "application/x-www-form-urlencoded" )
type MatrixTester ¶
type MatrixTester struct {
// contains filtered or unexported fields
}
MatrixTester is used for executing matrix tests.
func CreateMatrixTester ¶
func CreateMatrixTester() MatrixTester
CreateMatrixTester creates a new MatrixTester.
func (*MatrixTester) AddTestCase ¶
func (mt *MatrixTester) AddTestCase( tReq RequestTester, tRes CaseResponse)
AddTestCase adds a test case which consists of a RequestTester and a CaseResponse. When executing [Do] the RequestTester will be executed and its response will be compared to the provided CaseResponse.
type ParallelOperation ¶
ParallelOperation is a operation executed while waiting for a new message coming from the server.
type RequestTester ¶
A RequestTester is used to test a certain HTTP request.
func CreateRequestTester ¶
func CreateRequestTester( handler http.Handler, method, path string, pathValues ...any, ) RequestTester
CreateRequestTester creates a new RequestTester.
func (*RequestTester) AddCookie ¶
func (tReq *RequestTester) AddCookie(cookie *http.Cookie)
AddCookie adds a cookie to a RequestTester. Can be used multiple times for adding several cookies.
func (RequestTester) Copy ¶
func (tReq RequestTester) Copy() RequestTester
Copy creates a copy of a RequestTester in order to easily test similar requests.
func (*RequestTester) Do ¶
func (tReq *RequestTester) Do(t *testing.T) *http.Response
Do executes a RequestTester returning the response of a request and providing the returned data to rsData.
func (*RequestTester) SetContentType ¶
func (tReq *RequestTester) SetContentType(contentType ContentType)
SetContentType sets the content type of a RequestTester.
func (*RequestTester) SetData ¶
func (tReq *RequestTester) SetData(data any)
SetData sets the request data of a RequestTester.
func (*RequestTester) SetFollowRedirect ¶
func (tReq *RequestTester) SetFollowRedirect(follow bool)
SetFollowRedirect configures the request to follow or ignore redirects.
func (*RequestTester) SetQuery ¶
func (tReq *RequestTester) SetQuery(query url.Values)
SetQuery sets the query of a RequestTester.
func (*RequestTester) SetTestServer ¶
func (tReq *RequestTester) SetTestServer(ts *httptest.Server)
SetTestServer sets the test server of a RequestTester. This allows to reuse existing test servers.
type WebSocketTester ¶
type WebSocketTester struct {
// contains filtered or unexported fields
}
WebSocketTester is used for testing a websocket.
func CreateWebSocketTester ¶
func CreateWebSocketTester(handler http.Handler) WebSocketTester
CreateWebSocketTester creates a new WebSocketTester.
func (WebSocketTester) Do ¶
func (tWeb WebSocketTester) Do( t *testing.T, initialResponse any, parallelOperationResponse any, ) error
Do executes a WebSocketTester returning the response of the initialRequest and parallelOperation. An error is returned if the initialResponse can't be read.
func (*WebSocketTester) SetInitialMessage ¶
func (tWeb *WebSocketTester) SetInitialMessage(msg any)
SetInitialMessage sets the message to be sent when the connection is created.
func (*WebSocketTester) SetParallelOperation ¶
func (tWeb *WebSocketTester) SetParallelOperation(parallelOperation ParallelOperation)
SetParallelOperation sets operation to be executed while waiting for a new message coming from the server.