Documentation ¶
Overview ¶
Package testhelper container methods that are useful for writing unit tests.
Index ¶
- Variables
- func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte)
- func AssertDeepEquals(t *testing.T, expected, actual interface{})
- func AssertEquals(t *testing.T, expected, actual interface{})
- func AssertErr(t *testing.T, e error)
- func AssertIntGreaterOrEqual(t *testing.T, v1 int, v2 int)
- func AssertIntLesserOrEqual(t *testing.T, v1 int, v2 int)
- func AssertJSONEquals(t *testing.T, expectedJSON string, actual interface{})
- func AssertNoErr(t *testing.T, e error)
- func CheckByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte)
- func CheckDeepEquals(t *testing.T, expected, actual interface{})
- func CheckEquals(t *testing.T, expected, actual interface{})
- func CheckErr(t *testing.T, e error, expected ...interface{})
- func CheckJSONEquals(t *testing.T, expectedJSON string, actual interface{})
- func CheckNoErr(t *testing.T, e error)
- func Endpoint() string
- func SetupHTTP()
- func SetupPersistentPortHTTP(t *testing.T, port int)
- func TeardownHTTP()
- func TestBody(t *testing.T, r *http.Request, expected string)
- func TestFormValues(t *testing.T, r *http.Request, values map[string]string)
- func TestHeader(t *testing.T, r *http.Request, header string, expected string)
- func TestHeaderUnset(t *testing.T, r *http.Request, header string)
- func TestJSONRequest(t *testing.T, r *http.Request, expected string)
- func TestMethod(t *testing.T, r *http.Request, expected string)
Constants ¶
This section is empty.
Variables ¶
var ( // Mux is a multiplexer that can be used to register handlers. Mux *http.ServeMux // Server is an in-memory HTTP server for testing. Server *httptest.Server )
Functions ¶
func AssertByteArrayEquals ¶
AssertByteArrayEquals a convenience function for checking whether two byte arrays are equal
func AssertDeepEquals ¶
AssertDeepEquals - like Equals - performs a comparison - but on more complex structures that requires deeper inspection
func AssertEquals ¶
AssertEquals compares two arbitrary values and performs a comparison. If the comparison fails, a fatal error is raised that will fail the test
func AssertErr ¶ added in v0.11.0
AssertErr is a convenience function for checking whether an error value is nil
func AssertIntGreaterOrEqual ¶ added in v0.16.0
AssertIntGreaterOrEqual verifies that first value is greater or equal than second values
func AssertIntLesserOrEqual ¶ added in v0.16.0
AssertIntLesserOrEqual verifies that first value is lesser or equal than second values
func AssertJSONEquals ¶
AssertJSONEquals serializes a value as JSON, parses an expected string as JSON, and ensures that both are consistent. If they aren't, the expected and actual structures are pretty-printed and shown for comparison.
This is useful for comparing structures that are built as nested map[string]interface{} values, which are a pain to construct as literals.
func AssertNoErr ¶
AssertNoErr is a convenience function for checking whether an error value is an actual error
func CheckByteArrayEquals ¶
CheckByteArrayEquals a convenience function for silent checking whether two byte arrays are equal
func CheckDeepEquals ¶
CheckDeepEquals is similar to AssertDeepEquals, except with a non-fatal error
func CheckEquals ¶
CheckEquals is similar to AssertEquals, except with a non-fatal error
func CheckErr ¶ added in v1.3.0
CheckErr is similar to AssertErr, except with a non-fatal error. If expected errors are passed, this function also checks that an error in e's tree is assignable to one of them. The tree consists of e itself, followed by the errors obtained by repeatedly calling Unwrap.
CheckErr panics if expected contains anything other than non-nil pointers to either a type that implements error, or to any interface type.
func CheckJSONEquals ¶
CheckJSONEquals is similar to AssertJSONEquals, but nonfatal.
func CheckNoErr ¶
CheckNoErr is similar to AssertNoErr, except with a non-fatal error
func Endpoint ¶
func Endpoint() string
Endpoint returns a fake endpoint that will actually target the Mux.
func SetupPersistentPortHTTP ¶ added in v0.11.0
SetupPersistentPortHTTP prepares the Mux and Server listening specific port.
func TestFormValues ¶
TestFormValues ensures that all the URL parameters given to the http.Request are the same as values.
func TestHeader ¶
TestHeader checks that the header on the http.Request matches the expected value.
func TestHeaderUnset ¶ added in v0.22.0
TestHeaderUnset checks that the header on the http.Request doesn't exist.
func TestJSONRequest ¶
TestJSONRequest verifies that the JSON payload of a request matches an expected structure, without asserting things about whitespace or ordering.
Types ¶
This section is empty.