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 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) SetBody(body any)
- func (tReq *RequestTester) SetQuery(query map[string]string)
- 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 ¶ added in v0.1.1
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 ¶ added in v0.1.1
func NewCaseResponse(statusCode int, cookies []*http.Cookie, body any) CaseResponse
NewCaseResponse returns a new CaseResponse.
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 ¶ added in v0.1.1
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 ¶
type RequestTester struct {
// contains filtered or unexported fields
}
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) SetBody ¶ added in v0.1.1
func (tReq *RequestTester) SetBody(body any)
SetBody sets the request body of a RequestTester.
func (*RequestTester) SetQuery ¶
func (tReq *RequestTester) SetQuery(query map[string]string)
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 ¶ added in v0.1.1
type WebSocketTester struct {
// contains filtered or unexported fields
}
WebSocketTester is used for testing a websocket.
func CreateWebSocketTester ¶ added in v0.1.1
func CreateWebSocketTester(handler http.Handler) WebSocketTester
CreateWebSocketTester creates a new WebSocketTester.
func (WebSocketTester) Do ¶ added in v0.1.1
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 ¶ added in v0.1.1
func (tWeb *WebSocketTester) SetInitialMessage(msg any)
SetInitialMessage sets the message to be sent when the connection is created.
func (*WebSocketTester) SetParallelOperation ¶ added in v0.1.1
func (tWeb *WebSocketTester) SetParallelOperation(parallelOperation ParallelOperation)
SetParallelOperation sets operation to be executed while waiting for a new message coming from the server.