helpers

package
v1.0.2-0...-a203117 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertAPIRequest

func AssertAPIRequest(
	t testing.TB,
	testServer *HTTPServer,
	request *APIRequest,
	expectedResponse *APIResponse,
)

AssertAPIRequest creates new server with provided mockStorage (which you can keep nil so it will be created automatically) and provided serverConfig(you can leave it empty to use the default one) sends api request and checks api response (see docs for APIRequest and APIResponse)

func AssertStringsAreEqualJSON

func AssertStringsAreEqualJSON(t testing.TB, expected, got string)

AssertStringsAreEqualJSON checks whether strings represent the same JSON (whitespaces and order of elements doesn't matter) and asserts error otherwise

func CheckResponseBodyJSON

func CheckResponseBodyJSON(t testing.TB, expectedJSON string, body io.ReadCloser)

CheckResponseBodyJSON checks if body is the same json as in expected (ignores whitespaces, newlines, etc) also validates both expected and body to be a valid json

func ExecuteRequest

func ExecuteRequest(testServer *HTTPServer, req *http.Request) *httptest.ResponseRecorder

ExecuteRequest executes http request on a testServer

func FailOnError

func FailOnError(t testing.TB, err error)

FailOnError wraps result of function with one argument

func FrisbyExpectItemInArray

func FrisbyExpectItemInArray(fieldName string, expectedItem interface{}) frisby.ExpectFunc

FrisbyExpectItemInArray returns checker function for frisby to check if item is in the array Example:

frisby.Create("test creating organization"). Get(apiURL + "/organization"). Send(). ExpectStatus(200). Expect(helpers.FrisbyExpectItemInArray("organizations", 55))

will check if 55 is in organizations, like here `{"organizations": [1, 2, 3, 55], "status": "ok"}`

func JSONUnmarshalStrict

func JSONUnmarshalStrict(data []byte, outObj interface{}) error

JSONUnmarshalStrict unmarshales json and returns error if some field exist in data, but not in outObj

func RunTestWithTimeout

func RunTestWithTimeout(t *testing.T, test TestFunctionPtr, timeToRun time.Duration)

RunTestWithTimeout runs test with timeToRun timeout and fails if it wasn't in time

Types

type APIRequest

type APIRequest struct {
	Method             string
	APIPrefix          string
	Endpoint           string
	EndpointArgs       []interface{}
	Body               string
	UserID             types.UserID
	XRHIdentity        string
	AuthorizationToken string
}

APIRequest is a request to api to use in AssertAPIRequest

(required) Method is an http method (required) Endpoint is an endpoint without api prefix EndpointArgs are the arguments to pass to endpoint template (leave empty if endpoint is not a template) Body is a string body (leave empty to not send) UserID is a user id for methods requiring user id (leave empty to not use it) XRHIdentity is an authentication token (leave empty to not use it) AuthorizationToken is an authentication token (leave empty to not use it)

type APIResponse

type APIResponse struct {
	StatusCode  int
	Body        string
	BodyChecker func(t testing.TB, expected, got string)
	Headers     map[string]string
}

APIResponse is an expected api response to use in AssertAPIRequest

StatusCode is an expected http status code (leave empty to not check for status code) Body is an expected body string (leave empty to not check for body) BodyChecker is a custom body checker function (leave empty to use default one - CheckResponseBodyJSON)

type HTTPServer

type HTTPServer interface {
	Initialize()
}

type TestFunctionPtr

type TestFunctionPtr = func(*testing.T)

TestFunctionPtr pointer to test function

Jump to

Keyboard shortcuts

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