testhelpers

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Crypter

func Crypter(t *testing.T) crypter.Crypter

Crypter returns a crypter.Crypter that has been configured with a test key

func DELETE

func DELETE(t *testing.T, svr http.Handler, addr string, body io.Reader, assertFns ...RecTestFn)

DELETE is a test utility to test a svr handles a DELETE call.

func DecodeBody

func DecodeBody(t *testing.T, r io.Reader, v interface{})

DecodeBody is a helper for decoding an io.reader (i.e. response body) into the destination type (v).

func Do

func Do(t *testing.T, method, addr string, body io.Reader) *http.Response

Do is a test helper for creating a req and sending that req to a test server.

func EncodeBody

func EncodeBody(t *testing.T, v interface{}) *bytes.Buffer

EncodeBody is a helper func for encoding a type into an bytes.Buffer type. Can be used for a response body or whatever else. The returned buffer can be written or read from as needed.

func GET

func GET(t *testing.T, svr http.Handler, addr string, assertFns ...RecTestFn)

GET is a test utility to test a svr handles a GET call.

func GetURL

func GetURL(t *testing.T, addr string) *url.URL

GetURL is a helper for parsing a string address.

func HEAD(t *testing.T, svr http.Handler, addr string, assertFns ...RecTestFn)

HEAD is a test utility to test a svr handles a HEAD call.

func HTTP

func HTTP(
	t *testing.T, svr http.Handler,
	method, addr string, body io.Reader,
	assertFns ...RecTestFn,
)

HTTP is a test utility to test a svr handles whatever call you provide it.

func JSONPrettyPrint

func JSONPrettyPrint(t *testing.T, v interface{})

JSONPrettyPrint pretty prints a json body in all its glory.

func NewRandomPort

func NewRandomPort(t *testing.T) (string, string)

NewRandomPort identifies a port on the localhost interface for use during tests and returns the string in host:port format as well as a url with an http scheme. It uses similar methodology to how the net/http/httptest server chooses a port.

func PATCH

func PATCH(t *testing.T, svr http.Handler, addr string, body io.Reader, assertFns ...RecTestFn)

PATCH is a test utility to test a svr handles a PATCH call.

func POST

func POST(t *testing.T, svr http.Handler, addr string, body io.Reader, assertFns ...RecTestFn)

POST is a test utility to test a svr handles a POST call.

func PUT

func PUT(t *testing.T, svr http.Handler, addr string, body io.Reader, assertFns ...RecTestFn)

PUT is a test utility to test a svr handles a PUT call.

Types

type RecTestFn

type RecTestFn func(t *testing.T, w *httptest.ResponseRecorder)

RecTestFn is a functional option to run assertions against the response of the http request being made by the HTTP func or its relatives.

func ContentType

func ContentType(contentType string) RecTestFn

ContentType verifies that the Content-Type of the response matches the contentType provided.

func Header(key, val string) RecTestFn

Header verifies that the header of the response with key matches the val provided.

func Resp

func Resp(assertFn func(t *testing.T, w *httptest.ResponseRecorder)) RecTestFn

Resp allows the body to be asserted and viewed per the function.

func Status

func Status(status int) RecTestFn

Status verifies the status code of the response matches the status provided.

func StatusAccepted

func StatusAccepted() RecTestFn

StatusAccepted verifies the status code is 202 (Status Accepted).

func StatusBadRequest

func StatusBadRequest() RecTestFn

StatusBadRequest verifies the sttus code is 400 (Bad Request).

func StatusCreated

func StatusCreated() RecTestFn

StatusCreated verifies the status code is 201 (Status Created).

func StatusInternalServerError

func StatusInternalServerError() RecTestFn

StatusInternalServerError verifies the status code is 500 (Status Internal Server Error).

func StatusNoContent

func StatusNoContent() RecTestFn

StatusNoContent verifies the status code is 204 (Status No Content).

func StatusNotFound

func StatusNotFound() RecTestFn

StatusNotFound verifies the status code is 404 (Status Not Found).

func StatusNotImplemented

func StatusNotImplemented() RecTestFn

StatusNotImplemented verifies the status code is 501 (Status Not Implemented).

func StatusOK

func StatusOK() RecTestFn

StatusOK verifies the status code is 200 (Status OK).

func StatusUnprocessableEntity

func StatusUnprocessableEntity() RecTestFn

StatusUnprocessableEntity verifies the status code is 422 (Status Unprocessable Entity).

type WorkDir

type WorkDir struct {
	// contains filtered or unexported fields
}

WorkDir creates a new temporary working directory while storing the current working directory for restoration at a later time

func NewWorkingDir

func NewWorkingDir() (*WorkDir, error)

NewWorkingDir creates a new temporary working directory

func (*WorkDir) Cleanup

func (t *WorkDir) Cleanup() error

Cleanup restores the original working directory and cleans up the tmp dir

func (*WorkDir) Join

func (t *WorkDir) Join(file string) string

Join appends the relative path specified by file to the original working directory

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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