Documentation ¶
Index ¶
- func AssertAPIRequest(t testing.TB, testServer ServerInitializer, APIPrefix string, ...)
- func AssertReportResponsesEqual(t testing.TB, expected, got []byte)
- func AssertStringsAreEqualJSON(t testing.TB, expected, got string)
- func CheckResponseBodyJSON(t testing.TB, expectedJSON string, body io.ReadCloser)
- func CleanAfterGock(t testing.TB)
- func ExecuteRequest(testServer ServerInitializer, req *http.Request) *httptest.ResponseRecorder
- func FailOnError(t testing.TB, err error)
- func FrisbyExpectItemInArray(fieldName string, expectedItem interface{}) frisby.ExpectFunc
- func GockExpectAPIRequest(t *testing.T, baseURL string, request *APIRequest, response *APIResponse)
- func JSONUnmarshalStrict(data []byte, outObj interface{}) error
- func MustGobSerialize(t testing.TB, obj interface{}) []byte
- func NewGockAPIEndpointMatcher(endpoint string) func(req *http.Request, _ *gock.Request) (bool, error)
- func NewGockRequestMatcher(t *testing.T, method string, url string, body interface{}) func(*http.Request, *gock.Request) (bool, error)
- func RunTestWithTimeout(t *testing.T, test TestFunctionPtr, timeToRun time.Duration)
- func ToJSONPrettyString(obj interface{}) string
- func ToJSONString(obj interface{}) string
- type APIRequest
- type APIResponse
- type BodyChecker
- type ServerInitializer
- type TestFunctionPtr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertAPIRequest ¶
func AssertAPIRequest( t testing.TB, testServer ServerInitializer, APIPrefix string, request *APIRequest, expectedResponse *APIResponse, )
AssertAPIRequest sends sends api request and checks api response (see docs for APIRequest and APIResponse) to the provided testServer using the provided APIPrefix
func AssertReportResponsesEqual ¶
AssertReportResponsesEqual checks if reports in answer are the same
func AssertStringsAreEqualJSON ¶
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 CleanAfterGock ¶ added in v1.2.1
CleanAfterGock cleans after gock library and prints all unmatched requests
func ExecuteRequest ¶
func ExecuteRequest(testServer ServerInitializer, req *http.Request) *httptest.ResponseRecorder
ExecuteRequest executes http request on a testServer
func FailOnError ¶
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 GockExpectAPIRequest ¶ added in v1.2.1
func GockExpectAPIRequest(t *testing.T, baseURL string, request *APIRequest, response *APIResponse)
GockExpectAPIRequest makes gock expect the request with the baseURL and sends back the response
func JSONUnmarshalStrict ¶
JSONUnmarshalStrict unmarshales json and returns error if some field exist in data, but not in outObj
func MustGobSerialize ¶ added in v1.2.1
MustGobSerialize serializes an object using gob or panics
func NewGockAPIEndpointMatcher ¶
func NewGockAPIEndpointMatcher(endpoint string) func(req *http.Request, _ *gock.Request) (bool, error)
NewGockAPIEndpointMatcher returns new matcher for github.com/h2non/gock to match endpoint with any args
func NewGockRequestMatcher ¶ added in v1.2.1
func NewGockRequestMatcher( t *testing.T, method string, url string, body interface{}, ) func(*http.Request, *gock.Request) (bool, error)
NewGockRequestMatcher returns a new matcher for github.com/h2non/gock to match requests with provided method, url and body(the same types as body in APIRequest(see the docs))
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
func ToJSONPrettyString ¶ added in v1.2.1
func ToJSONPrettyString(obj interface{}) string
ToJSONPrettyString converts anything to indented JSON or panics if it's not possible
func ToJSONString ¶
func ToJSONString(obj interface{}) string
ToJSONString converts anything to JSON or panics if it's not possible
Types ¶
type APIRequest ¶
type APIRequest struct { Method string Endpoint string EndpointArgs []interface{} Body interface{} UserID types.UserID OrgID types.OrgID XRHIdentity string AuthorizationToken string ExtraHeaders http.Header }
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 request body which can be a string or []byte (leave empty to not send) UserID is a user id for methods requiring user id (leave empty to not use it) OrgID is an org id for methods requiring it to be in token (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 interface{} BodyChecker BodyChecker 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 which can be a string or []byte(leave empty to not check for body) BodyChecker is a custom body checker function (leave empty to use default one - CheckResponseBodyJSON)
type BodyChecker ¶ added in v1.2.1
BodyChecker represents body checker type for api response
type ServerInitializer ¶
ServerInitializer is interface which is implemented for any server having Initialize method
type TestFunctionPtr ¶
TestFunctionPtr pointer to test function