testsupport

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UserTokenKey      = []byte("0123456789abcdef0123456789abcdef")
	OtherUserTokenKey = []byte("fedcba9876543210fedcba9876543210")
)

Functions

func AdvisoryLocks added in v0.23.0

func AdvisoryLocks(t *testing.T, tx pgx.Tx) int

AdvisoryLocks returns how many advisory locks tx's connection holds.

func Begin added in v0.23.0

func Begin(t *testing.T, pool *pgxpool.Pool) pgx.Tx

Begin begins a transaction that is rolled back when the test ends, unless it was committed.

func Claims

func Claims() auth.Claims

Claims are the claims of a valid user token, as auth-api issues it.

func EncodedKey

func EncodedKey(key []byte) []byte

func HTTPModule

func HTTPModule(t *testing.T, opts []modules.Option) *httpModule.Module

HTTPModule configures a bootstrapify http module with opts and registers ErrorResponse, the way a service does before defining its routes.

func InsertItem added in v0.23.0

func InsertItem(ctx context.Context, db execer, subscriberID uuid.UUID) error

InsertItem inserts one item of the subscriber on db, a pool or a tx.

func InsertItems added in v0.23.0

func InsertItems(t *testing.T, pool *pgxpool.Pool, subscriberID uuid.UUID, n int)

func ItemCount added in v0.23.0

func ItemCount(t *testing.T, pool *pgxpool.Pool, subscriberID uuid.UUID) int

ItemCount returns the subscriber's committed items.

func NoContent

func NoContent(c *gin.Context)

func Postgres added in v0.23.0

func Postgres(t *testing.T) *pgxpool.Pool

Postgres returns a pool on TEST_DATABASE_DSN whose search_path is a schema of the test's own, holding an items(subscriber_id) table. The schema is dropped when the test ends. It skips without the DSN, and fails without it in CI.

func Request

func Request(t *testing.T, handler http.Handler, method, path string, headers map[string]string) int

Request sends a request with the headers to the handler and returns the response status.

func SaveConcurrently added in v0.23.0

func SaveConcurrently(
	t *testing.T,
	pool *pgxpool.Pool,
	n int,
	save func(ctx context.Context, tx pgx.Tx) error,
) []error

SaveConcurrently begins n transactions, then runs save on all of them at once and commits each one save returned nil for. It returns each save's error, or the error of beginning or committing its transaction.

func SignToken

func SignToken(t *testing.T, method jwt.SigningMethod, claims auth.Claims, key any) string

func TraefikRouterMiddlewares

func TraefikRouterMiddlewares(t *testing.T, path string) map[string][]string

TraefikRouterMiddlewares reads an exported Traefik routes file and returns the middlewares of each router, by router name.

func UserToken

func UserToken(t *testing.T, claims auth.Claims) string

UserToken signs the claims the way auth-api does.

func Validator

func Validator(t *testing.T) *auth.Validator

Types

type ItemCounter added in v0.23.0

type ItemCounter struct {
	Calls int
	// contains filtered or unexported fields
}

ItemCounter counts a subscriber's items on a tx, the way a consumer's tx-bound repository does, and records how often it was called.

func CountItems added in v0.23.0

func CountItems(tx pgx.Tx, subscriberID uuid.UUID) *ItemCounter

func (*ItemCounter) Count added in v0.23.0

func (c *ItemCounter) Count(ctx context.Context) (int, error)

type Result

type Result struct {
	Status    int
	Error     *response.ErrorResponse
	IsReached bool
	Context   context.Context
}

Result is what a request served by Serve produced. Context is the request context the handler saw, nil when the handler was not reached.

func Serve

func Serve(t *testing.T, headers map[string]string, mw ...gin.HandlerFunc) Result

Serve sends a GET request with the headers through bootstrapify's ErrorResponse, then mw, then a handler that records the request context.

func ServeError added in v0.23.0

func ServeError(t *testing.T, err error) Result

ServeError serves a request whose handler passes err to c.Error, through bootstrapify's ErrorResponse, the way a controller reports an error.

Jump to

Keyboard shortcuts

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