testUtil

package
v0.0.0-...-bf4388d Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2015 License: Apache-2.0, Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package testUtil has helpers to be used with unit tests

Index

Constants

View Source
const InvalidJSONPayload = -1

InvalidJSONPayload indicates an invalid payload

View Source
const InvalidJSONPayloadString = "{Invalid JSON payload"

InvalidJSONPayloadString indicates an invalid payload

Variables

This section is empty.

Functions

func Assert

func Assert(tb testing.TB, condition bool, msg string, v ...interface{})

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

func Equals(tb testing.TB, exp, act interface{})

Equals fails the test if exp is not equal to act. Code was copied from https://github.com/benbjohnson/testing MIT license

func HeaderValuesEqual

func HeaderValuesEqual(t *testing.T, req *http.Request, name string, expectedValue string)

HeaderValuesEqual verifies the header values are equal to the expected value.

func IsNil

func IsNil(tb testing.TB, act interface{})

IsNil ensures that the act interface is nil otherwise an error is raised.

func UserHomeDir

func UserHomeDir(t *testing.T) string

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

func (TestReadCloser) Close

func (r TestReadCloser) Close() error

Close is an empty impl

func (TestReadCloser) Read

func (r TestReadCloser) Read(p []byte) (n int, err error)

Read will read from the buffer

Jump to

Keyboard shortcuts

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