Documentation
¶
Index ¶
- Constants
- func ChdirRepoRoot(t *testing.T)
- func DialBufconn(t *testing.T, serve func(net.Listener) error) *grpc.ClientConn
- func GenerateSigningKey(t *testing.T) string
- func NewUUIDv7(t *testing.T) uuid.UUID
- func RegisterUnimplementedAuth(s *grpc.Server)
- func RegisterUnimplementedLookup(s *grpc.Server)
- func RequireWithAwait(t *testing.T, predicate func(ct *assert.CollectT))
- func Serving(context.Context) (healthpb.HealthCheckResponse_ServingStatus, error)
- func WithMetadata(kv ...string) context.Context
- type JWKSServer
- type JWKSServerOption
- type LogCapture
- type MinimalServiceConfig
Constants ¶
const ( HeaderA = "x-a-token" HeaderB = "x-b-token" )
HeaderA and HeaderB are the service-token header names of two services hosted on one gRPC server in tests: A is auth-shaped, B data-access-shaped.
const DynamicClientOrganizationID = "00000000-0000-7000-8000-000000000000"
Variables ¶
This section is empty.
Functions ¶
func ChdirRepoRoot ¶
ChdirRepoRoot changes the working directory to the repository root for the duration of the test. This lets the config loaders resolve ./configs regardless of which package directory the test runs from.
func DialBufconn ¶ added in v1.26.0
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 GenerateSigningKey ¶ added in v1.45.3
GenerateSigningKey returns a freshly generated RSA-2048 private key encoded the way jwk.NewDefaultProvider expects it: base64-encoded PKCS#8 PEM.
func RegisterUnimplementedAuth ¶ added in v1.105.0
RegisterUnimplementedAuth and RegisterUnimplementedLookup register auth's AuthService and data-access's LookupService with their Unimplemented servers, so a request that gets through the server's chain is answered with codes.Unimplemented by the handler itself: a passed check reads differently from a rejected one.
func RegisterUnimplementedLookup ¶ added in v1.105.0
func RequireWithAwait ¶ added in v1.42.4
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.
func Serving ¶ added in v1.105.0
func Serving(context.Context) (healthpb.HealthCheckResponse_ServingStatus, error)
Serving is a health check that always reports SERVING, in the shape of grpcserver.Check, for a registration whose health is not what the test is about.
func WithMetadata ¶ added in v1.105.0
WithMetadata is a background context carrying kv as outgoing gRPC metadata, for a call that has to present a header such as a service token.
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, opts ...JWKSServerOption) *JWKSServer
NewJWKSServer generates an RSA key, starts an httptest server serving its public JWKS, and returns both. The server is closed via t.Cleanup.
type JWKSServerOption ¶ added in v1.44.1
type JWKSServerOption func(*jwksServerConfig)
JWKSServerOption configures NewJWKSServer.
func WithBlockUntil ¶ added in v1.44.1
func WithBlockUntil(release <-chan struct{}) JWKSServerOption
WithBlockUntil makes the server not respond to /keys until release closes, so a test can deterministically control when the JWKS becomes fetchable instead of racing a background fetch against its own assertions.
type LogCapture ¶ added in v1.45.2
type LogCapture struct {
// contains filtered or unexported fields
}
LogCapture holds log output written during a test. Its buffer is guarded by a mutex because a server under test logs from its own goroutine while the test reads from another.
func CaptureJSONLogs ¶ added in v1.45.2
func CaptureJSONLogs(t *testing.T) *LogCapture
CaptureJSONLogs redirects the logrus standard logger — the one labkit's access loggers write to unless told otherwise — into a buffer with a JSON formatter, so a test can assert on single fields instead of a rendered line. The original output and formatter are restored as test cleanup.
type MinimalServiceConfig ¶ added in v1.42.4
type MinimalServiceConfig struct {
GRPCAddress string `mapstructure:"grpc_address"`
}
MinimalServiceConfig stands in for a service config in tests. GRPCAddr lets a test model a service that listens on gRPC only.
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
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package clientfixture converts OAuth client fixtures into the registration the registry accepts.
|
Package clientfixture converts OAuth client fixtures into the registration the registry accepts. |
|
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. |