testtx

package
v0.13.4-beta.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package testtx provides a shared transmit-sink recorder for tests. Every caller of txgovernor.TxSink (kiss, agw, beacon, digipeater) previously carried a near-identical mutex+slice "fake sink" in its test file; this package is the one canonical implementation.

Recorder satisfies txgovernor.TxSink and collects every Submit invocation. It supports an optional per-submit hook so tests that need to block on a specific number of frames, or signal a waiter channel, can do so without reimplementing the recorder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capture

type Capture struct {
	Channel uint32
	Frame   *ax25.Frame
	Source  txgovernor.SubmitSource
}

Capture is one recorded Submit invocation.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder is a txgovernor.TxSink that stores every Submit call for later inspection. Safe for concurrent use.

func NewRecorder

func NewRecorder() *Recorder

NewRecorder builds an empty Recorder.

func (*Recorder) Captures

func (r *Recorder) Captures() []Capture

Captures returns a copy of every recorded Submit call in order.

func (*Recorder) Frames

func (r *Recorder) Frames() []*ax25.Frame

Frames returns a copy of the captured frames in order. Convenience for tests that only care about the payload.

func (*Recorder) Last

func (r *Recorder) Last() *Capture

Last returns a copy of the most recent capture, or nil if none.

func (*Recorder) Len

func (r *Recorder) Len() int

Len returns the number of captured Submit calls.

func (*Recorder) OnSubmit

func (r *Recorder) OnSubmit(fn func(Capture)) *Recorder

OnSubmit installs a hook invoked after each Submit call with the capture that was just appended. Passing nil clears the hook. Returns the receiver for chained construction:

sink := testtx.NewRecorder().OnSubmit(func(c testtx.Capture) {
    signal <- struct{}{}
})

func (*Recorder) Reset

func (r *Recorder) Reset()

Reset clears the captured history. Useful in table-driven tests that want to reuse a recorder across sub-tests.

func (*Recorder) Submit

func (r *Recorder) Submit(_ context.Context, channel uint32, frame *ax25.Frame, source txgovernor.SubmitSource) error

Submit implements txgovernor.TxSink. It records the invocation, invokes the installed hook (if any) outside the lock, and returns nil. Production sinks that want to simulate errors should build on this type rather than replacing it.

Jump to

Keyboard shortcuts

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