tests_utils

package
v5.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdaptRequest

func AdaptRequest(r HttpRequestComponents) http.Request

func JsonStr

func JsonStr[T any](obj *T) string

func JsonStrFromIoReadCloser

func JsonStrFromIoReadCloser(readCloser io.ReadCloser) string

func Make200Response

func Make200Response[T any](body *T) *http.Response

func MakeResponse

func MakeResponse(status int, body interface{}) *http.Response

func MakeResponseWithStatus

func MakeResponseWithStatus[T any](status int, body *T) *http.Response

func MockDoRequestNoBody

func MockDoRequestNoBody(httpRequester *mocks.HttpClientRequester, expectedRequest http.Request, res *http.Response, err error)

func MockDoRequestWithBody

func MockDoRequestWithBody[T any](mockRequest *MockRequestWithBodyParams[T])

func ParseReaderToStruct

func ParseReaderToStruct[T any](v io.Reader, t *T) error

func ParseStructToIoReadCloser

func ParseStructToIoReadCloser[T any](v *T) io.ReadCloser

func Pointer

func Pointer[T any](v T) *T

func RunGlideExternalApiTestCases

func RunGlideExternalApiTestCases[ResponseStructT any](
	t *testing.T,
	testCases []GlideExternalApiTestCase[ResponseStructT],
)

Types

type GlideExternalApiTestCase

type GlideExternalApiTestCase[T any] struct {
	Name                   string
	Arrange                func(client glide.Client)
	Act                    func(client glide.Client) (*T, error)
	ExpectedRequest        HttpRequestComponents
	MockResponse           *http.Response
	ErrorInsteadOfResponse error
	Assert                 func(*testing.T, *T, error)
}

type HttpRequestComponents

type HttpRequestComponents struct {
	Method string
	Url    string
	Body   interface{}
}

this type is mainly to keep the body an un-modified original struct

func MakeGetRequest

func MakeGetRequest(url string) HttpRequestComponents

func MakeRequest

func MakeRequest[T any](method string, url string, body *T) HttpRequestComponents

func MakeRequestWithNoBody

func MakeRequestWithNoBody(method string, url string) HttpRequestComponents

type MockRequestWithBodyParams

type MockRequestWithBodyParams[T any] struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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