errorreporttest

package
v0.0.0-...-acbe8ed Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

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

View Source
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

func NewClient(tb testing.TB) (*sentry.Client, *Transport, error)

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

func NewHub(tb testing.TB) (*sentry.Hub, *Transport, error)

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) Close

func (t *Transport) Close()

Close implements sentry.Transport.

func (*Transport) Configure

func (t *Transport) Configure(sentry.ClientOptions)

Configure implements sentry.Transport.

func (*Transport) Events

func (t *Transport) Events() []*sentry.Event

Events returns a snapshot of the events captured so far.

func (*Transport) Flush

func (t *Transport) Flush(time.Duration) bool

Flush implements sentry.Transport. Nothing is buffered, so it always succeeds.

func (*Transport) FlushWithContext

func (t *Transport) FlushWithContext(context.Context) bool

FlushWithContext implements sentry.Transport.

func (*Transport) Len

func (t *Transport) Len() int

Len returns how many events have been captured.

func (*Transport) SendEvent

func (t *Transport) SendEvent(event *sentry.Event)

SendEvent implements sentry.Transport by recording the event.

Jump to

Keyboard shortcuts

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