Documentation ¶
Overview ¶
Package testUtil has helpers to be used with unit tests
Index ¶
- Constants
- func Assert(tb testing.TB, condition bool, msg string, v ...interface{})
- func CreateDeleteTestRequestServer(t *testing.T, expectedAuthTokenValue string, urlEndsWith string) *httptest.Server
- func CreateGetJSONTestRequestServer(t *testing.T, expectedAuthTokenValue string, jsonResponsePayload string, ...) *httptest.Server
- func CreateGetJSONTestRequestServerVerifyStatusAndURL(t *testing.T, token string, responseStatus int, jsonValue string, ...) *httptest.Server
- func CreateGetJSONTestRequestServerVerifyURL(t *testing.T, token string, jsonValue string, urlEndsWith string) *httptest.Server
- func CreateGetJSONTestRequestServerWithMockObject(t *testing.T, token string, mockResponseObject interface{}, urlEndsWith string) *httptest.Server
- func CreateGetJSONTestRequestServerWithMockObjectAndStatus(t *testing.T, token string, responseStatus int, mockResponseObject interface{}, ...) *httptest.Server
- func CreateGetJSONTestRequestServerWithStatus(t *testing.T, expectedAuthTokenValue string, responseStatus int, ...) *httptest.Server
- func CreateGetTestRequestServer(t *testing.T, expectedAuthTokenValue string, responseStatus int, ...) *httptest.Server
- func CreateHeadTestRequestServer(t *testing.T, expectedAuthTokenValue string, responseStatus int, ...) *httptest.Server
- func CreatePostJSONTestRequestServer(t *testing.T, expectedAuthTokenValue string, outputResponseJSONPayload string, ...) *httptest.Server
- func Equals(tb testing.TB, exp, act interface{})
- func HeaderValuesEqual(t *testing.T, req *http.Request, name string, expectedValue string)
- func IsNil(tb testing.TB, act interface{})
- func UserHomeDir(t *testing.T) string
- type TestReadCloser
Constants ¶
const InvalidJSONPayload = -1
InvalidJSONPayload indicates an invalid payload
const InvalidJSONPayloadString = "{Invalid JSON payload"
InvalidJSONPayloadString indicates an invalid payload
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert fails the test if the condition is false. Code was copied from https://github.com/benbjohnson/testing MIT license
func CreateDeleteTestRequestServer ¶
func CreateDeleteTestRequestServer(t *testing.T, expectedAuthTokenValue string, urlEndsWith string) *httptest.Server
CreateDeleteTestRequestServer creates a http.Server that can be used to test Delete requests.
func CreateGetJSONTestRequestServer ¶
func CreateGetJSONTestRequestServer(t *testing.T, expectedAuthTokenValue string, jsonResponsePayload string, verifyRequest func(*http.Request)) *httptest.Server
CreateGetJSONTestRequestServer creates a httptest.Server that can be used to test GetJson requests. Just specify the token, json payload that is to be read by the response, and a verification func that can be used to do additional validation of the request that is built
func CreateGetJSONTestRequestServerVerifyStatusAndURL ¶
func CreateGetJSONTestRequestServerVerifyStatusAndURL(t *testing.T, token string, responseStatus int, jsonValue string, urlEndsWith string) *httptest.Server
CreateGetJSONTestRequestServerVerifyStatusAndURL creates a http.Server that can be used to test GetJSON requests. Specify the token, the response status, the marshaled json payload of response object, and the expected ending url.
func CreateGetJSONTestRequestServerVerifyURL ¶
func CreateGetJSONTestRequestServerVerifyURL(t *testing.T, token string, jsonValue string, urlEndsWith string) *httptest.Server
CreateGetJSONTestRequestServerVerifyURL creates a http.Server that can be used to test GetJSON requests. Specify the token, the marshaled json payload of response object, and the expected ending url.
func CreateGetJSONTestRequestServerWithMockObject ¶
func CreateGetJSONTestRequestServerWithMockObject(t *testing.T, token string, mockResponseObject interface{}, urlEndsWith string) *httptest.Server
CreateGetJSONTestRequestServerWithMockObject creates a http.Server that can be used to test GetJSON requests. Specify the token, response object which will be marshaled to a json payload and the expected ending url.
func CreateGetJSONTestRequestServerWithMockObjectAndStatus ¶
func CreateGetJSONTestRequestServerWithMockObjectAndStatus(t *testing.T, token string, responseStatus int, mockResponseObject interface{}, urlEndsWith string) *httptest.Server
CreateGetJSONTestRequestServerWithMockObjectAndStatus creates a http.Server that can be used to test GetJSON requests. Specify the token, the response status, response object which will be marshaled to a json payload and the expected ending url.
func CreateGetJSONTestRequestServerWithStatus ¶
func CreateGetJSONTestRequestServerWithStatus(t *testing.T, expectedAuthTokenValue string, responseStatus int, jsonResponsePayload string, verifyRequest func(*http.Request)) *httptest.Server
CreateGetJSONTestRequestServerWithStatus creates a httptest.Server that can be used to test GetJson requests. Just specify the token, the response status, json payload that is to be read by the response, and a verification func that can be used to do additional validation of the request that is built
func CreateGetTestRequestServer ¶
func CreateGetTestRequestServer(t *testing.T, expectedAuthTokenValue string, responseStatus int, headers http.Header, body []byte, verifyRequest func(*http.Request)) *httptest.Server
CreateGetTestRequestServer creates a httptest.Server that can be used with Get. The user is required to specify the entire body and headers of the response.
func CreateHeadTestRequestServer ¶
func CreateHeadTestRequestServer(t *testing.T, expectedAuthTokenValue string, responseStatus int, headers http.Header, body []byte, verifyRequest func(*http.Request)) *httptest.Server
CreateHeadTestRequestServer creates a httptest.Server that can be used with Head. The user is required to specify the entire body and headers of the response.
func CreatePostJSONTestRequestServer ¶
func CreatePostJSONTestRequestServer(t *testing.T, expectedAuthTokenValue string, outputResponseJSONPayload string, expectedRequestURLEndsWith string, expectedRequestBody string) *httptest.Server
CreatePostJSONTestRequestServer creates a http.Server that can be used to test PostJson requests. Specify the token, response json payload and the url and request body that is expected.
func Equals ¶
Equals fails the test if exp is not equal to act. Code was copied from https://github.com/benbjohnson/testing MIT license
func HeaderValuesEqual ¶
HeaderValuesEqual verifies the header values are equal to the expected value.
func UserHomeDir ¶
UserHomeDir returns current user home directory including ending path separator, for example, "/Users/johndoe/" on Mac.
Types ¶
type TestReadCloser ¶
type TestReadCloser struct { ErrorOnCallRead bool // contains filtered or unexported fields }
TestReadCloser is a test implementation of a io.Reader and io.Closer
func NewTestReadCloser ¶
func NewTestReadCloser(data []byte) TestReadCloser
NewTestReadCloser creates a new reader with the specified bytes