testutil

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2025 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicTB

func PanicTB() *panicTB

PanicTB is an implementation for testing.TB that panics when an error is logged or FailNow is called. This is useful to inject into test helpers in example tests where no *testing.T is available.

If env is set with `RIVER_DEBUG=true`, output is logged to os.Stderr (Stderr instead of Stdout to not interfere with example test output).

Doesn't fully implement testing.TB. Functions where it's used should take the more streamlined TestingTB instead.

Types

type JobArgsReflectKind added in v0.24.0

type JobArgsReflectKind[TKind any] struct{}

JobArgsReflectKind can be embedded on a struct to implement JobArgs such that the job's kind will be the name of TKind. Typically, for convenience TKind will be the same type that does the embedding. Use of JobArgsReflectKind may not be typical, but in combination with WorkFunc, it allows the entirety of a job args and worker pair to be implemented inside the body of a function.

type InFuncWorkFuncArgs struct {
	testutil.JobArgsReflectKind[InFuncWorkFuncArgs]
	Message `json:"message"`
}

AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[WorkFuncArgs]) error {
	...

Its major downside compared to a normal JobArgs implementation is that it's possible to easily break things accidentally by renaming its type, deploying, and then finding that the worker will no longer work any jobs that were inserted before the deploy. It also depends on reflection, which likely makes it marginally slower.

We're not sure yet whether it's appropriate to expose this publicly, so for now we've localized it to the test suite only. When a test case needs a job type that won't be reused, it's preferable to make use of JobArgsReflectKind so the type doesn't pollute the global namespace.

func (JobArgsReflectKind[TKind]) Kind added in v0.24.0

func (a JobArgsReflectKind[TKind]) Kind() string

type MockT added in v0.22.0

type MockT struct {
	Failed bool
	// contains filtered or unexported fields
}

MockT mocks TestingTB. It's used to let us verify our test helpers.

func NewMockT added in v0.22.0

func NewMockT(tb TestingTB) *MockT

NewMockT initializes a new MockT. It takes another TestingTB which is usually something like a *testing.T and where logs are emitted to along with being internalized and retrievable on LogOutput.

func (*MockT) Errorf added in v0.22.0

func (t *MockT) Errorf(format string, args ...any)

func (*MockT) FailNow added in v0.22.0

func (t *MockT) FailNow()

func (*MockT) Helper added in v0.22.0

func (t *MockT) Helper()

func (*MockT) Log added in v0.22.0

func (t *MockT) Log(args ...any)

func (*MockT) LogOutput added in v0.22.0

func (t *MockT) LogOutput() string

func (*MockT) Logf added in v0.22.0

func (t *MockT) Logf(format string, args ...any)

func (*MockT) Name added in v0.23.0

func (t *MockT) Name() string

type TestingTB

type TestingTB interface {
	Errorf(format string, args ...any)
	FailNow()
	Helper()
	Log(args ...any)
	Logf(format string, args ...any)
	Name() string
}

TestingT is an interface wrapper around *testing.T that's implemented by all of *testing.T, *testing.F, and *testing.B.

It's used internally to verify that River's test assertions are working as expected.

Jump to

Keyboard shortcuts

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