gophercloud: Index | Files | Directories

package testhelper

import ""

Package testhelper container methods that are useful for writing unit tests.


Package Files

convenience.go doc.go http_responses.go


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

func AssertByteArrayEquals Uses

func AssertByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte)

AssertByteArrayEquals a convenience function for checking whether two byte arrays are equal

func AssertDeepEquals Uses

func AssertDeepEquals(t *testing.T, expected, actual interface{})

AssertDeepEquals - like Equals - performs a comparison - but on more complex structures that requires deeper inspection

func AssertEquals Uses

func AssertEquals(t *testing.T, expected, actual interface{})

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 Uses

func AssertErr(t *testing.T, e error)

AssertErr is a convenience function for checking that an error occurred

func AssertJSONEquals Uses

func AssertJSONEquals(t *testing.T, expectedJSON string, actual interface{})

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 Uses

func AssertNoErr(t *testing.T, e error)

AssertNoErr is a convenience function for checking whether an error value is an actual error

func AssertNotNil Uses

func AssertNotNil(t *testing.T, actual interface{})

AssertNotNil is a convenience function for checking whether given value is not nil

func CheckByteArrayEquals Uses

func CheckByteArrayEquals(t *testing.T, expectedBytes []byte, actualBytes []byte)

CheckByteArrayEquals a convenience function for silent checking whether two byte arrays are equal

func CheckDeepEquals Uses

func CheckDeepEquals(t *testing.T, expected, actual interface{})

CheckDeepEquals is similar to AssertDeepEquals, except with a non-fatal error

func CheckEquals Uses

func CheckEquals(t *testing.T, expected, actual interface{})

CheckEquals is similar to AssertEquals, except with a non-fatal error

func CheckErr Uses

func CheckErr(t *testing.T, e error)

CheckErr is a convenience function for checking that an error occurred, except with a non-fatal error

func CheckJSONEquals Uses

func CheckJSONEquals(t *testing.T, expectedJSON string, actual interface{})

CheckJSONEquals is similar to AssertJSONEquals, but nonfatal.

func CheckNoErr Uses

func CheckNoErr(t *testing.T, e error)

CheckNoErr is similar to AssertNoErr, except with a non-fatal error

func Endpoint Uses

func Endpoint() string

Endpoint returns a fake endpoint that will actually target the Mux.

func SetupHTTP Uses

func SetupHTTP()

SetupHTTP prepares the Mux and Server.

func TeardownHTTP Uses

func TeardownHTTP()

TeardownHTTP releases HTTP-related resources.

func TestBody Uses

func TestBody(t *testing.T, r *http.Request, expected string)

TestBody verifies that the request body matches an expected body.

func TestFormValues Uses

func TestFormValues(t *testing.T, r *http.Request, values map[string]string)

TestFormValues ensures that all the URL parameters given to the http.Request are the same as values.

func TestHeader Uses

func TestHeader(t *testing.T, r *http.Request, header string, expected string)

TestHeader checks that the header on the http.Request matches the expected value.

func TestJSONRequest Uses

func TestJSONRequest(t *testing.T, r *http.Request, expected string)

TestJSONRequest verifies that the JSON payload of a request matches an expected structure, without asserting things about whitespace or ordering.

func TestMethod Uses

func TestMethod(t *testing.T, r *http.Request, expected string)

TestMethod checks that the Request has the expected method (e.g. GET, POST).



Package testhelper imports 12 packages (graph) and is imported by 24 packages. Updated 2016-07-14. Refresh now. Tools for package owners.