testutil

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertErrorResponse

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

func AssertHeader

func AssertHeader(t *testing.T, rec *httptest.ResponseRecorder, header, expectedValue string)

func AssertHeaderExists

func AssertHeaderExists(t *testing.T, rec *httptest.ResponseRecorder, header string)

func AssertJSONResponse

func AssertJSONResponse(t *testing.T, rec *httptest.ResponseRecorder, target any)

func AssertResponseBody

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

func AssertResponseContains

func AssertResponseContains(t *testing.T, rec *httptest.ResponseRecorder, substring string)

func AssertStatusCode

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

func AssertSuccessResponse

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

func CleanupDatabase

func CleanupDatabase(t *testing.T, ctx context.Context, pg *gfrpostgres.Postgres)

func CleanupFunc

func CleanupFunc(t *testing.T, fn func())

func Context

func Context(t *testing.T) context.Context

func ContextWithCustomTimeout

func ContextWithCustomTimeout(t *testing.T, timeout time.Duration) (context.Context, context.CancelFunc)

func ContextWithDeadline

func ContextWithDeadline(t *testing.T, deadline time.Time) (context.Context, context.CancelFunc)

func ContextWithTimeout

func ContextWithTimeout(t *testing.T) (context.Context, context.CancelFunc)

func Eventually

func Eventually(t *testing.T, condition func() bool, timeout time.Duration, interval time.Duration)

func EventuallyWithMessage

func EventuallyWithMessage(t *testing.T, condition func() bool, timeout time.Duration, interval time.Duration, message string)

func MustParseJSONResponse

func MustParseJSONResponse(t *testing.T, rec *httptest.ResponseRecorder, target interface{})

func Parallel

func Parallel(t *testing.T)

func ParseJSONResponse

func ParseJSONResponse(rec *httptest.ResponseRecorder, target interface{}) error

func RandomEmail

func RandomEmail() string

func RandomInt

func RandomInt(minVal, maxVal int64) int64

func RandomString

func RandomString(length int) string

func RequireEnv

func RequireEnv(t *testing.T, key string) string

func RunMigrations

func RunMigrations(ctx context.Context, pool *gfrpostgres.Postgres, migrationPath string) error

func SetupEchoContext

func SetupEchoContext(
	t *testing.T,
	opts *Options,
) (*echo.Context, *httptest.ResponseRecorder, *http.Request)

func SetupEchoContextWithAuth

func SetupEchoContextWithAuth(
	t *testing.T,
	opts *Options,
	token string,
) (*echo.Context, *httptest.ResponseRecorder, *http.Request)

func SetupEchoContextWithJSON

func SetupEchoContextWithJSON(
	t *testing.T,
	method string,
	path string,
	body interface{},
) (*echo.Context, *httptest.ResponseRecorder, *http.Request)

func SkipIfShort

func SkipIfShort(t *testing.T)

Types

type Options

type Options struct {
	Method        string            // HTTP method (GET, POST, etc.)
	Path          string            // Request path
	Body          []byte            // Request body
	Headers       map[string]string // Custom headers
	QueryParams   map[string]string // Query parameters
	PathParams    map[string]string // Path parameters (e.g., :id)
	ContentType   string            // Content-Type header (defaults to application/json)
	SkipRequestID bool              // Skip auto-generating X-Request-ID header
}

type PostgresTestContainer

type PostgresTestContainer struct {
	Container testcontainers.Container
	User      string
	Password  string
	Host      string
	Database  string
	Port      nat.Port
}

func SetupPostgresContainer

func SetupPostgresContainer(t *testing.T) *PostgresTestContainer

func (*PostgresTestContainer) ConnectionString

func (c *PostgresTestContainer) ConnectionString() string

func (*PostgresTestContainer) DSN

func (c *PostgresTestContainer) DSN() string

type ValkeyTestContainer

type ValkeyTestContainer struct {
	Container testcontainers.Container
	Host      string
	Port      nat.Port
}

func SetupValkeyContainer

func SetupValkeyContainer(t *testing.T) *ValkeyTestContainer

func (*ValkeyTestContainer) Address

func (c *ValkeyTestContainer) Address() string

Jump to

Keyboard shortcuts

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