Documentation
¶
Index ¶
- func AssertSuccess[T any](t *testing.T, result *api.BusinessError) (data T)
- type Engine
- type Request
- func (r *Request) AssertErrValidation(t *testing.T)
- func (r *Request) AssertError(t *testing.T, expectedError *api.BusinessError)
- func (r *Request) AssertSuccess(t *testing.T, data ...any)
- func (r *Request) AssertSuccessGet(t *testing.T, dataPtr any)
- func (r *Request) MustExec() *api.BusinessError
- func (r *Request) MustExecRaw() *httptest.ResponseRecorder
- func (r *Request) MustWithJSONBody(body any) *Request
- func (r *Request) MustWithMultipart(fields map[string]string, files ...map[string]string) *Request
- func (r *Request) WithAuth(accessToken string) *Request
- func (r *Request) WithQueryParams(params map[string]string) *Request
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertSuccess ¶
func AssertSuccess[T any](t *testing.T, result *api.BusinessError) (data T)
AssertSuccess asserts to unmarshal the business error and returns specific type of data.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine provides utilities to create HTTP request for unit tests.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is used to send HTTP request in unit tests.
func NewRequest ¶
NewRequest creates a request with specified method and URL.
Note, query params are set by `WithQueryParams` instead of concatenated with URL.
func (*Request) AssertErrValidation ¶
AssertErrValidation sends HTTP request and asserts api.ErrCodeValidation retrieved.
func (*Request) AssertError ¶
func (r *Request) AssertError(t *testing.T, expectedError *api.BusinessError)
AssertError sends HTTP request and asserts an expected business error.
func (*Request) AssertSuccess ¶
AssertSuccess sends HTTP request and asserts success with optional data.
func (*Request) AssertSuccessGet ¶
AssertSuccessGet sends HTTP request and asserts to unmarshal data with specified `dataPtr`.
func (*Request) MustExec ¶
func (r *Request) MustExec() *api.BusinessError
MustExec sends HTTP request and unmarshal response body to `api.BusinessError`.
func (*Request) MustExecRaw ¶
func (r *Request) MustExecRaw() *httptest.ResponseRecorder
MustExecRaw sends HTTP request and requires 200 OK response.
It panics on any error, or response status code is not 200.
func (*Request) MustWithJSONBody ¶
MustWithJSONBody builds JSON body with content type application/json.
func (*Request) MustWithMultipart ¶
MustWithMultipart builds form data in request body.
func (*Request) WithQueryParams ¶
WithQueryParams builds query params to concatenate with URL.
This helper is intended for a single build step in test code. If you call it multiple times, the URL will be extended again, so prefer constructing all query params before the first call.