utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertError

func AssertError(t *testing.T, err error)

AssertError checks if an error occurred

func AssertErrorResponse

func AssertErrorResponse(t *testing.T, rec *httptest.ResponseRecorder, expectedStatus int, expectedError string)

AssertErrorResponse asserts error response properties

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, rec *httptest.ResponseRecorder, expectedStatus int)

AssertJSONResponse asserts common JSON response properties

func AssertNoError

func AssertNoError(t *testing.T, err error)

AssertNoError checks if no error occurred

func AssertResponseBody

func AssertResponseBody(t *testing.T, rec *httptest.ResponseRecorder, expected any)

AssertResponseBody asserts that the response body matches the expected value

func AssertResponseCode

func AssertResponseCode(t *testing.T, rec *httptest.ResponseRecorder, expectedCode int)

AssertResponseCode checks if the response has the expected status code

func AssertResponseHeader

func AssertResponseHeader(t *testing.T, rec *httptest.ResponseRecorder, key, expectedValue string)

AssertResponseHeader checks if the response has the expected header value

func AssertSuccessResponse

func AssertSuccessResponse(t *testing.T, rec *httptest.ResponseRecorder, expectedStatus int)

AssertSuccessResponse asserts success response properties

func NewJSONRequest

func NewJSONRequest(method, path string, body any) (*http.Request, error)

NewJSONRequest creates a new JSON request for testing

func NewTestContext

func NewTestContext(e *echo.Echo, req *http.Request) (echo.Context, *httptest.ResponseRecorder)

NewTestContext creates a new Echo context for testing

func ParseJSONResponse

func ParseJSONResponse(rec *httptest.ResponseRecorder, v any) error

ParseJSONResponse parses a JSON response from a test recorder

Types

type TestSetup

type TestSetup struct {
	T      *testing.T
	Echo   *echo.Echo
	Logger logging.Logger
}

TestSetup contains common test setup utilities

func NewTestSetup

func NewTestSetup(t *testing.T) *TestSetup

NewTestSetup creates a new test setup with common configurations

func (*TestSetup) AssertNoError

func (ts *TestSetup) AssertNoError(err error, msgAndArgs ...any)

AssertNoError asserts that the given error is nil

func (*TestSetup) Close

func (ts *TestSetup) Close() error

Close performs any necessary cleanup

func (*TestSetup) RequireNoError

func (ts *TestSetup) RequireNoError(err error, msgAndArgs ...any)

RequireNoError requires that the given error is nil

Jump to

Keyboard shortcuts

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