testhttp

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustGET

func MustGET(ctx context.Context, t *testing.T, addr string) *http.Response

MustGET performs an HTTP GET request to the specified address and returns the response. It is used in tests to make sure the request is successful, otherwise it will fail the test.

func MustPost

func MustPost(ctx context.Context, t *testing.T, addr, contentType string, body io.Reader) *http.Response

func MustReadFullyJSON

func MustReadFullyJSON[T ~*E, E any](t *testing.T, resp *http.Response, target T)

MustReadFullyJSON reads the response body from an HTTP response and populates the target variable with the JSON data. It is used in tests to ensure that the response body is successfully read and parsed as JSON, otherwise it will fail the test. The resp parameter is the HTTP response that contains the JSON data to be read. The target parameter is the variable where the parsed JSON data will be stored. The function returns the target variable with the JSON data. If there is an error reading or parsing the JSON data, the function will fail the test and return an error message.

func MustReadFullyString

func MustReadFullyString(t *testing.T, resp *http.Response) string

MustReadFullyString reads all the data from the specified `io.ReadCloser` and returns it as a string. If there is an error while reading or converting to string, it returns an empty string and the error.

func ReadFully

func ReadFully(resp *http.Response) ([]byte, error)

ReadFully reads all the data from the specified `io.ReadCloser` and returns it as a byte slice. If there is an error while reading, it returns `nil` and the error.

func ReadFullyJSON

func ReadFullyJSON[T ~*E, E any](resp *http.Response, target T) (err error)

ReadFullyJSON reads the response body from an HTTP response and populates the target variable with the JSON data. The resp parameter is the HTTP response that contains the JSON data to be read. The target parameter is the variable where the parsed JSON data will be stored. The function returns an error if there is a problem reading or parsing the JSON data.

func ReadFullyString

func ReadFullyString(resp *http.Response) (string, error)

ReadFullyString reads all the data from the specified `io.ReadCloser` and returns it as a string. If there is an error while reading or converting to string, it returns an empty string and the error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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