Documentation
¶
Overview ¶
Package errorreporttest provides a capturing Sentry transport for tests.
Tests that care about error reporting assert on the *real* *sentry.Event the real client produces — scope application, BeforeSend, the lot — with only the network hop replaced. Mocking our own wrappers instead would happily keep passing while Sentry received nothing, which is exactly the failure mode spec 2026-08-20-10 was written about.
NewHub returns a hub of its own rather than calling sentry.Init, so each test owns its client and its events and can still run with t.Parallel(). Bind the hub onto the context under test (sentry.SetHubOnContext) — every reporting path in this codebase looks there first.
Index ¶
- Constants
- type Transport
- func (t *Transport) Close()
- func (t *Transport) Configure(sentry.ClientOptions)
- func (t *Transport) Events() []*sentry.Event
- func (t *Transport) Flush(time.Duration) bool
- func (t *Transport) FlushWithContext(context.Context) bool
- func (t *Transport) Len() int
- func (t *Transport) SendEvent(event *sentry.Event)
Constants ¶
const TestDSN = "https://public@example.invalid/1"
TestDSN is a syntactically valid DSN pointing nowhere. A DSN is required for the client to build its event pipeline; the capturing transport means nothing is ever sent.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is a sentry.Transport that records events instead of sending them.
func NewClient ¶
NewClient builds a real Sentry client whose events land in the returned Transport.
The client is closed through tb.Cleanup: since sentry-go v0.49.0 dropped the DisableLogs/DisableMetrics options, a client built with a custom transport always starts the log and metric batcher goroutines, and only Close() stops them. Without the cleanup they outlive every test and trip the goleak checks the packages under test run.
func NewHub ¶
NewHub builds a real Sentry client bound to a fresh hub, with a capturing transport. Put the hub on the context under test.
func (*Transport) Configure ¶
func (t *Transport) Configure(sentry.ClientOptions)
Configure implements sentry.Transport.
func (*Transport) Flush ¶
Flush implements sentry.Transport. Nothing is buffered, so it always succeeds.
func (*Transport) FlushWithContext ¶
FlushWithContext implements sentry.Transport.