Documentation
¶
Overview ¶
Package lysclient contains types and functions to help test a REST API which was created using lys functions.
Index ¶
- func DoToValue[T any](ctx context.Context, client http.Client, method string, targetUrl string) (val T, err error)
- func DoToValueTester[T any](ctx context.Context, h http.Handler, method string, targetUrl string) (val T, err error)
- func GetSlice[T any](client http.Client, targetUrl string) (s []T, err error)
- func GetSliceTester[T any](ctx context.Context, h http.Handler, targetUrl string) (s []T, err error)
- func MustDoToValue[T any](ctx context.Context, t testing.TB, h http.Handler, method string, ...) (val T)
- func MustGetFile(ctx context.Context, t testing.TB, h http.Handler, targetUrl string)
- func MustGetFileWithHeaders(ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (body []byte, headers http.Header)
- func MustGetSlice[T any](ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (s []T)
- func MustGetValue[T any](ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (val T)
- func MustPostToValue[inT, outT any](ctx context.Context, t testing.TB, h http.Handler, method string, ...) (val outT)
- func PostSliceToValueTester[inT, outT any](ctx context.Context, h http.Handler, method string, targetUrl string, ...) (val outT, err error)
- func PostToValue[inT, outT any](ctx context.Context, client http.Client, method string, targetUrl string, ...) (val outT, err error)
- func PostToValueTester[inT, outT any](ctx context.Context, h http.Handler, method string, targetUrl string, item inT) (val outT, err error)
- type GetMetadata
- type ItemSResp
- func GetItemResp(client http.Client, targetUrl string) (itemResp ItemSResp, err error)
- func GetItemRespTester(ctx context.Context, h http.Handler, targetUrl string) (itemResp ItemSResp, err error)
- func MustGetItemResp(ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (itemResp ItemSResp)
- type SliceResp
- type ValueResp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoToValue ¶
func DoToValue[T any](ctx context.Context, client http.Client, method string, targetUrl string) (val T, err error)
DoToValue sends a request without a body to targetUrl. It expects a T in response
func DoToValueTester ¶
func DoToValueTester[T any](ctx context.Context, h http.Handler, method string, targetUrl string) (val T, err error)
DoToValueTester sends a request without a body to targetUrl using a test handler. It expects a T in response
func GetSliceTester ¶ added in v0.3.32
func GetSliceTester[T any](ctx context.Context, h http.Handler, targetUrl string) (s []T, err error)
GetSliceTester GETs the target Url using a test handler. It expects a slice of T in response
func MustDoToValue ¶
func MustDoToValue[T any](ctx context.Context, t testing.TB, h http.Handler, method string, targetUrl string) (val T)
MustDoToValue sends a request without a body to targetUrl using a test handler. It expects a T in response and will fail on any error
func MustGetFile ¶ added in v0.1.5
MustGetFile GETs the target Url using a test handler. It expects a response with file output headers and will fail on any error
func MustGetFileWithHeaders ¶ added in v0.3.36
func MustGetFileWithHeaders(ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (body []byte, headers http.Header)
MustGetFileWithHeaders GETs the target Url using a test handler and returns the body and response headers. It expects file output headers and will fail on any error
func MustGetSlice ¶ added in v0.3.32
func MustGetSlice[T any](ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (s []T)
MustGetSlice GETs the target Url using a test handler. It expects a slice of T in response and will fail on any error
func MustGetValue ¶ added in v0.3.22
func MustGetValue[T any](ctx context.Context, t testing.TB, h http.Handler, targetUrl string) (val T)
MustGetValue GETs the target Url using a test handler. It expects a single T in response and will fail on any error
func MustPostToValue ¶
func MustPostToValue[inT, outT any](ctx context.Context, t testing.TB, h http.Handler, method string, targetUrl string, item inT) (val outT)
MustPostToValue sends a POST/PUT/PATCH request to targetUrl using a test handler with an inT as the body. It expects an outT in response and will fail on any error
func PostSliceToValueTester ¶ added in v0.3.32
func PostSliceToValueTester[inT, outT any](ctx context.Context, h http.Handler, method string, targetUrl string, items []inT) (val outT, err error)
PostSliceToValueTester sends a POST/PUT/PATCH request to targetUrl using a test handler with an inT slice as the body. It expects an outT in response
func PostToValue ¶
func PostToValue[inT, outT any](ctx context.Context, client http.Client, method string, targetUrl string, item inT) (val outT, err error)
PostToValue sends a POST/PUT/PATCH request to targetUrl with an inT as the body. It expects an outT in response
func PostToValueTester ¶
func PostToValueTester[inT, outT any](ctx context.Context, h http.Handler, method string, targetUrl string, item inT) (val outT, err error)
PostToValueTester sends a POST/PUT/PATCH request to targetUrl using a test handler with an inT as the body. It expects an outT in response
Types ¶
type GetMetadata ¶ added in v0.1.46
type GetMetadata struct {
Count int `json:"count"`
TotalCount int64 `json:"total_count"`
TotalCountIsEstimated bool `json:"total_count_is_estimated"`
}
GetMetadata contains the metadata for a GET request which returns a slice of items (db records)
type ItemSResp ¶ added in v0.3.32
type ItemSResp struct {
Status string `json:"status"`
Data []map[string]any `json:"data"`
GetMetadata *GetMetadata `json:"metadata,omitempty"` // only used for GET many
ErrDescription string `json:"err_description"`
}
ItemSResp is expected when StdResponse returns a slice of map[string]any
func GetItemResp ¶ added in v0.1.46
GetItemResp GETs the target Url. It expects an array of items in response