lysclient

package
v0.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 9 Imported by: 0

README

lysclient

Types and functions to help test a REST API which was created using lys functions.

Documentation

Overview

Package lysclient contains types and functions to help test a REST API which was created using lys functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DoToValue

func DoToValue[T any](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](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 GetArray

func GetArray[T any](client http.Client, targetUrl string) (arr []T, err error)

GetArray GETs the target Url. It expects an array of T in response

func GetArrayTester

func GetArrayTester[T any](h http.Handler, targetUrl string) (arr []T, err error)

GetArrayTester GETs the target Url using a test handler. It expects an array of T in response

func MustDoToValue

func MustDoToValue[T any](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 MustGetArray

func MustGetArray[T any](t testing.TB, h http.Handler, targetUrl string) (arr []T)

MustGetArray GETs the target Url using a test handler. It expects an array of T in response and will fail on any error

func MustGetFile added in v0.1.5

func MustGetFile(t testing.TB, h http.Handler, targetUrl string)

MustGetFile GETs the target Url using a test handler. It expects a response with file output headers and will fail on any error

func MustPostToValue

func MustPostToValue[inT, outT any](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 PostArrayToValueTester added in v0.3.8

func PostArrayToValueTester[inT, outT any](h http.Handler, method string, targetUrl string, items []inT) (val outT, err error)

PostArrayToValueTester 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](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](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 ArrayResp

type ArrayResp[T any] struct {
	Status         string `json:"status"`
	Data           []T    `json:"data"`
	ErrDescription string `json:"err_description"`
}

ArrayResp is expected when StdResponse returns an array of T

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"`
}

type ItemAResp

type ItemAResp 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"`
}

ItemAResp is expected when StdResponse returns an array of items (db records)

func GetItemResp added in v0.1.46

func GetItemResp(client http.Client, targetUrl string) (itemResp ItemAResp, err error)

GetItemResp GETs the target Url. It expects an array of items in response

func GetItemRespTester added in v0.1.46

func GetItemRespTester(h http.Handler, targetUrl string) (itemResp ItemAResp, err error)

GetItemRespTester GETs the target Url using a test handler. It expects an array of items in response

func MustGetItemResp added in v0.1.46

func MustGetItemResp(t testing.TB, h http.Handler, targetUrl string) (itemResp ItemAResp)

MustGetItemResp GETs the target Url using a test handler. It expects an array of items in response and will fail on any error

type ValueResp

type ValueResp[T any] struct {
	Status         string `json:"status"`
	Data           T      `json:"data"`
	ErrDescription string `json:"err_description"`
}

ValueResp is expected when StdResponse returns a T

Jump to

Keyboard shortcuts

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