gztest

package
v8.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertBackendErrorCode

func AssertBackendErrorCode(testName string, bslice *[]byte, errCode int, t *testing.T)

AssertBackendErrorCode is a function that tries to unmarshal a backend's ErrMsg and compares to given error code

func AssertRoute

func AssertRoute(method, route string, code int, t *testing.T) (*[]byte, bool)

AssertRoute is a helper function that checks for a valid route \param[in] method One of "GET", "PATCH", "PUT", "POST", "DELETE", "OPTIONS" \param[in] route The URL string \param[in] code The expected result HTTP code \param[in] t Testing pointer \return[out] *[]byte A pointer to a bytes slice containing the response body. \return[out] bool A flag indicating if the operation was ok.

func AssertRouteMultipleArgs

func AssertRouteMultipleArgs(method string, route string, body *bytes.Buffer, code int, signedToken *string, contentType string, t *testing.T) (*[]byte, bool)

AssertRouteMultipleArgs is a helper function that checks for a valid route. \param[in] method One of "GET", "PATCH", "PUT", "POST", "DELETE" \param[in] route The URL string \param[in] body The body to send in the request, or nil \param[in] code The expected response HTTP code \param[in] signedToken JWT token as base64 string, or nil. \param[in] contentType The expected response content type \param[in] t Test pointer \return[out] *[]byte A pointer to a bytes slice containing the response body. \return[out] bool A flag indicating if the operation was ok.

func AssertRouteWithBody

func AssertRouteWithBody(method, route string, body *bytes.Buffer, code int, t *testing.T) (*[]byte, bool)

AssertRouteWithBody is a helper function that checks for a valid route \return[out] *[]byte A pointer to a bytes slice containing the response body. \return[out] bool A flag indicating if the operation was ok.

func CreateTmpFolderWithContents

func CreateTmpFolderWithContents(folderName string, files []FileDesc) (string, error)

CreateTmpFolderWithContents creates a tmp folder with the given files and returns the path to the created folder. See type fileDesc above.

func GetIndentedTraceToTest

func GetIndentedTraceToTest() string

GetIndentedTraceToTest returns a formatted and indented string containing the file and line number of each stack frame leading from the current test to the assert call that failed.

func InvalidRouteTestHelper

func InvalidRouteTestHelper(t *testing.T)

InvalidRouteTestHelper is a helper test function that just invokes an invalid route

func OptionsTestHelper

func OptionsTestHelper(uris []string, routenames []string, t *testing.T)

OptionsTestHelper is a helper function to test the autogenerated OPTIONS urls, given a set of Routes' URIs. This function should be called from each specific project that defines routes.

func SendMultipartMethod

func SendMultipartMethod(testName string, t *testing.T, method, uri string, jwt *string,
	params map[string]string, files []FileDesc) (respCode int,
	bslice *[]byte, ok bool)

SendMultipartMethod executes a multipart POST/PUT/PATCH request with the given form fields and multipart files, and returns the received http status code, the response body, and a success flag.

func SendMultipartPOST

func SendMultipartPOST(testName string, t *testing.T, uri string, jwt *string,
	params map[string]string, files []FileDesc) (respCode int,
	bslice *[]byte, ok bool)

SendMultipartPOST executes a multipart POST request with the given form fields and multipart files, and returns the received http status code, the response body, and a success flag.

func SetupTest

func SetupTest(_router http.Handler)

SetupTest - Setup helper function

Types

type AssertResponse

type AssertResponse struct {
	Ok           bool
	RespRecorder *httptest.ResponseRecorder
	BodyAsBytes  *[]byte
}

AssertResponse - response of AssertRouteMultipleArgsStruct func.

func AssertRouteMultipleArgsStruct

func AssertRouteMultipleArgsStruct(args RequestArgs, expCode int, contentType string, t *testing.T) *AssertResponse

AssertRouteMultipleArgsStruct is a convenient helper function that accepts input arguments as a struct, allowing us to keep extending the number of args without changing the func signature and the corresponding invocation code everywhere. \param[in] args RequestArgs struct \param[in] expCode The expected response HTTP code \param[in] contentType The expected response content type \param[in] t Test pointer \return[out] *AssertResponse A pointer to a AssertResponse struct with the response.

type FileDesc

type FileDesc struct {
	Path     string
	Contents string
}

FileDesc describes a file to be created. It is used by func CreateTmpFolderWithContents and sendMultipartPOST. Fields: path: is the file path to be sent in the multipart form. contents: is the string contents to write in the file. Note: if contents value is ":dir" then a Directory will be created instead of a File. This is only valid when used with CreateTmpFolderWithContents func.

type RequestArgs

type RequestArgs struct {
	Method      string
	Route       string
	Body        *bytes.Buffer
	SignedToken *string
	Headers     map[string]string
}

RequestArgs - input arguments struct used by AssertRouteMultipleArgsStruct func.

Jump to

Keyboard shortcuts

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