commontest

package
v0.0.0-...-589bc69 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package commontest holds methods which are helpful when writing tests within mediocre-api

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIStarterKit

func APIStarterKit() util.Cmder

APIStarterKit returns an initialized *API and a Cmder which can be used as generic entities for testing

func AssertReq

func AssertReq(
	t *testing.T, mux http.Handler, method, endpoint, body, expectedBody string,
)

AssertReq uses the stretchr/assert package to assert that the result of calling Req with the given arguments has a 200 response code and the given expectedBody

func AssertReqErr

func AssertReqErr(
	t *testing.T, mux http.Handler, method, endpoint, body string,
	err common.ExpectedErr,
)

AssertReqErr uses the stretchr/assert package to assert that the result of calling Req with the given arguments has a response code equal to the given ExpectedErr's and a body the same as well

func AssertReqJSON

func AssertReqJSON(
	t *testing.T, mux http.Handler, method, endpoint, body string,
	dst interface{},
)

AssertReqJSON uses the stretchr/assert package to assert that the result of calling Req with the given arguments has a 200 response and a body which is unmarshaled into dst successfully.

func AssertReqRaw

func AssertReqRaw(
	t *testing.T, mux http.Handler, r *http.Request, expectedBody string,
)

AssertReqRaw uses the stretchr/assert package to assert that the result of executing the given *http.Request returns a 200 response code and the given expectedBody

func AssertReqRawJSON

func AssertReqRawJSON(
	t *testing.T, mux http.Handler, r *http.Request, dst interface{},
)

AssertReqRawJSON uses the stretchr/assert package to assert that the result of executing the given *http.Request returns a 200 response and a body which is unmarshaled into dst successfully.

func RandEmail

func RandEmail() string

RandEmail returns a string which could plausibly be an email (but definitely isn't a real one)

func RandStr

func RandStr() string

RandStr returns a string of random alphanumeric characters

func Req

func Req(
	t *testing.T, mux http.Handler, method, endpoint, body string,
) (
	int, string,
)

Req is a method which makes testing http requests easier. It makes the request with the given method and body against the given endpoint, returning the return status code and body

Types

This section is empty.

Jump to

Keyboard shortcuts

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