testutil

package
v1.42.6 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChdirRepoRoot

func ChdirRepoRoot(t *testing.T)

ChdirRepoRoot changes the working directory to the repository root for the duration of the test. This allows config.Load to resolve ./configs correctly regardless of which package directory the test runs from.

func DialBufconn added in v1.26.0

func DialBufconn(t *testing.T, serve func(net.Listener) error) *grpc.ClientConn

DialBufconn starts serve (typically a *grpc.Server's Serve method) on an in-process bufconn listener and returns a client connection to it, for tests that exercise a real gRPC server without binding a TCP port. Closing the connection is registered as test cleanup.

func NewUUIDv7 added in v1.27.0

func NewUUIDv7(t *testing.T) uuid.UUID

NewUUIDv7 generates a UUIDv7, failing the test on error.

func RequireWithAwait added in v1.42.4

func RequireWithAwait(t *testing.T, predicate func(ct *assert.CollectT))

RequireWithAwait retries predicate until it passes, for tests that poll a service booting in the background. require calls inside the predicate are safe: CollectT.FailNow exits the tick's goroutine via runtime.Goexit, so a failed tick retries instead of aborting the test.

Types

type JWKSServer added in v1.26.0

type JWKSServer struct {
	// URL is the endpoint serving the JWKS; point a userauth.Issuer.KeysURL
	// at it.
	URL string
	// contains filtered or unexported fields
}

JWKSServer is a local httptest server serving one freshly generated RSA key, for tests that need a JWT verifiable without a live GitLab instance. Mirrors the shape pkg/userauth's own tests sign against (see pkg/userauth/helpers_test.go); duplicated here since that helper code lives in _test.go files and isn't importable across packages.

func NewJWKSServer added in v1.26.0

func NewJWKSServer(t *testing.T) *JWKSServer

NewJWKSServer generates an RSA key, starts an httptest server serving its public JWKS, and returns both. The server is closed via t.Cleanup.

func (*JWKSServer) Sign added in v1.26.0

func (s *JWKSServer) Sign(t *testing.T, claims map[string]any) string

Sign returns claims signed with the server's private key (RS256).

type MinimalServiceConfig added in v1.42.4

type MinimalServiceConfig struct {
	GRPCAddress string `mapstructure:"grpc_address"`
}

MinimalServiceConfig satisfies config.ServiceConfig for integration tests that call base.MustInit only to reach the platform config (database, telemetry). The loader rejects a service name without a config section, so such tests bootstrap against "data-access" — the service their packages ship in. GRPCAddr exists because the loader demands a listen address; the tests never bind it.

func (MinimalServiceConfig) GRPCAddr added in v1.42.4

func (c MinimalServiceConfig) GRPCAddr() string

func (MinimalServiceConfig) Validate added in v1.42.4

func (MinimalServiceConfig) Validate() error

Directories

Path Synopsis
Package storagefake provides a configurable double for storage.Database, storage.Transaction, and storage.DBTX, for tests that exercise real service/server composition or drive sqlc-generated queries without a live DB connection.
Package storagefake provides a configurable double for storage.Database, storage.Transaction, and storage.DBTX, for tests that exercise real service/server composition or drive sqlc-generated queries without a live DB connection.

Jump to

Keyboard shortcuts

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