pomerium/internal/testutil/context.go
Caleb Doxsey 8935ed17fa
tests: use testcontainers (#5341)
* tests: use testcontainers for postgres

* tests: use testcontainers for minio

* remove gcs test

* try installing docker

* skip docker on macos
2024-10-30 13:33:30 -06:00

24 lines
483 B
Go

package testutil
import (
"context"
"testing"
"time"
)
// GetContext gets a context for a testing.T.
func GetContext(t *testing.T, maxWait time.Duration) context.Context {
t.Helper()
ctx := context.Background()
ctx, clearTimeout := context.WithTimeout(ctx, maxWait)
t.Cleanup(clearTimeout)
if deadline, ok := t.Deadline(); ok {
var clearDeadline context.CancelFunc
ctx, clearDeadline = context.WithDeadline(ctx, deadline)
t.Cleanup(clearDeadline)
}
return ctx
}