test

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package test helps a consumer look for a handler panic before one happens.

It proves nothing, and that is not modesty

A corpus and a fuzz target are testing, not verification. Passing means no panic was found on those inputs, never that the handler is panic-free. A helper that let somebody believe otherwise would be worse than no helper, because the module's panic counter would then read as impossible rather than as unexpected.

The module recovers a handler panic at the goroutine it owns, and the subscription is restarted under its own policy. That is a backstop, and a backstop is not a strategy. This package is the strategy.

Who it is for

A consumer, running Handler against the corpus in an ordinary unit test, and adding a fuzz target seeded from Corpus so the toolchain finds the rest.

A backend implementer wants gitlab.com/phpboyscout/go/messaging/conformance instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fuzz

func Fuzz(t T, h messaging.Handler, data []byte)

Fuzz runs h against one arbitrary payload, for use inside a Go fuzz target seeded from Corpus.

func FuzzHandler(f *testing.F) {
	for _, c := range test.Corpus() {
		f.Add(c.Delivery.Event.Data)
	}

	f.Fuzz(func(t *testing.T, data []byte) {
		test.Fuzz(t, myHandler, data)
	})
}

func Handler

func Handler(t T, h messaging.Handler)

Handler runs h against every case in Corpus and fails t if any of them panics.

It does NOT fail on a returned error. A handler returning an error is the contract working; a handler panicking is a defect, and conflating them would make this helper report a working handler as broken.

Types

type Case

type Case struct {
	// Name says what is adversarial about it. "A handler panicked" without
	// saying on which input is not actionable.
	Name string

	// Delivery is what the handler receives.
	Delivery messaging.Delivery
}

Case is one adversarial input, named so a failure says which one.

func Corpus

func Corpus() []Case

Corpus is the adversarial input set.

These are the panics that actually happen in a message handler, which is why they are enumerated once here rather than rediscovered in every consumer. Each is a shape a real broker can deliver: nothing here is impossible, only unwelcome.

type T

type T interface {
	Helper()
	Errorf(format string, args ...any)
}

T is the part of *testing.T this package needs.

An interface rather than the concrete type so that this package's own tests can assert on a failing run instead of failing themselves, which is the only way to know the harness can fail at all.

Jump to

Keyboard shortcuts

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