Documentation ¶
Index ¶
- func AsserErrorEqualsAny(t *testing.T, got error, expectAnyIn []error)
- func AssertErrorContains(t *testing.T, err error, shouldContain string)
- func AssertErrorEquals(t *testing.T, expected, got error)
- func AssertIntEquals(t testing.TB, expected, got int)
- func AssertIsError(t testing.TB, err error)
- func AssertMapsEqual(t *testing.T, got, expected map[string]interface{})
- func AssertStringArraysEqualNoOrder(t *testing.T, got, expected []string)
- func AssertStringContainsNoneOfTheSubstrings(t *testing.T, body string, nonExpectedStrings []string)
- func AssertStringContainsSubstringsInOrder(t *testing.T, body string, expectedStrings []string)
- func AssertStringContainsSubstringsNoOrder(t *testing.T, body string, expectedStrings []string)
- func AssertStringEquals(t testing.TB, expected, got string)
- func CheckFor500(t *testing.T, statusCode int)
- func ClearSlash(in string) string
- func ExpectError(t *testing.T, err error, msg string)
- func ExpectNoError(t *testing.T, err error, msg string)
- func JsonEqual(s1, s2 string) bool
- func NewTestServer(routes Routes) *httptest.Server
- type HandleFunc
- type Routes
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsserErrorEqualsAny ¶
AsserErrorEqualsAny checks if the actually error is equal to one in your error slice. You can use this function if you expect an error, but you do not exactly know which one Input:
t *testing.T The testing object, so we can call the return functions on it got error The error you actually got expectAnyIn []error All the errors that are a valid result
func AssertErrorContains ¶
AssertErrorContains checks if the given error contains the expected substring Input:
t *testing.T The testing object, so we can call the return functions on it err error The error you actually got shouldContain string The substring you expect in the error
func AssertErrorEquals ¶
AssertErrorEquals checks if the actually error is equal the expected one, by doing a string compare Input:
t *testing.T The testing object, so we can call the return functions on it expected error The error you expect got error The error you actually got
func AssertIntEquals ¶
AssertIntEquals checks if two strings are equal Input: t *testing.T The testing object, so we can call the return functions on it expected int The int you want to have got int The int you actually got from your test result
func AssertIsError ¶
AssertIsError checks if there is an error Input:
t *testing.T The testing object, so we can call the return functions on it err error The error you want to check for
func AssertMapsEqual ¶
AssertMapsEqual checks if two maps have the exact same content If a string is found, the test fails and we print the complete body Prints the complete body if wrong order is present Input:
t *testing.T The testing object, so we can call the return functions on it got map[string]interface{} The map you got expected map[string]interface{} The map you expect to have
func AssertStringArraysEqualNoOrder ¶
AssertStringArraysEqualNoOrder checks if two string slices are the same, but do not have the same order Input:
t *testing.T The testing object, so we can call the return functions on it got []string The slice you got expected []string The map you expect to have
func AssertStringContainsNoneOfTheSubstrings ¶
func AssertStringContainsNoneOfTheSubstrings(t *testing.T, body string, nonExpectedStrings []string)
AssertStringContainsNoneOfTheSubstrings checks if the given string contains any of the nonExpectedStrings If a string is found, the test fails and we print the complete body Prints the complete body if wrong order is present Input:
t *testing.T The testing object, so we can call the return functions on it body string The string you got nonExpectedStrings string The substrings you expect not to be in the body string
func AssertStringContainsSubstringsInOrder ¶
AssertStringContainsSubstringsInOrder checks if the given string contains all the expected strings in the right order. Prints the complete body if wrong order is present Input:
t *testing.T The testing object, so we can call the return functions on it body string The string you got expectedStrings string The substrings you expect to be in order in the body string
func AssertStringContainsSubstringsNoOrder ¶
AssertStringContainsSubstringsNoOrder checks if the given string contains all the expected strings, we do not care about the order Prints the complete body if wrong order is present Input:
t *testing.T The testing object, so we can call the return functions on it body string The string you got expectedStrings string The substrings you expect to be in the body string
func AssertStringEquals ¶
AssertStringEquals checks if two strings are equal Input: t *testing.T The testing object, so we can call the return functions on it expected string Te string you want to have got string The string you actually got from your test result
func CheckFor500 ¶
CheckFor500 checks if the given http status code equals StatusInternalServerError Input:
t *testing.T The testing object, so we can call the return functions on it statusCode int The http status code you want to check
func ClearSlash ¶
ClearSlash removes double forward and backward slashes from your string "//" => "/" && "\\" => "\" Input:
in string The string to clean
Output:
string The cleaned up string
func ExpectError ¶
ExpectError checks if the given error is != nil. If it is the msg is written to testing.Error
func ExpectNoError ¶
func checks if the given error is == nil. If it is not the msg is written to the testing.Error
func JsonEqual ¶
JsonEqual is an easy json compare function that tries to tell you if the given json strings are equal or not Input:
s1, s2 string The two json strings you want to compare
Output:
bool Bool that indicates if the strings are equal jsons (true if they are equal)
func NewTestServer ¶
NewTestServer creates a new go testing server with the given routes, so you can define more complex test server setups in no time Input
routes Routes The map of routes, that define your test server
Types ¶
type HandleFunc ¶
type HandleFunc func(*http.ResponseWriter, *http.Request)
HandleFunc the type of func that a typical go http handler has
type Routes ¶
type Routes map[string]HandleFunc
Routes is a map of functions, that help you to define your testserver Values:
key string The path of your route (e.g "/test/my/cool/func") func HandleFunc The go http handler that will be served at that route