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 ¶
- type Capture
- type Recorder
- func (r *Recorder) Captures() []Capture
- func (r *Recorder) Frames() []*ax25.Frame
- func (r *Recorder) Last() *Capture
- func (r *Recorder) Len() int
- func (r *Recorder) OnSubmit(fn func(Capture)) *Recorder
- func (r *Recorder) Reset()
- func (r *Recorder) Submit(_ context.Context, channel uint32, frame *ax25.Frame, ...) error
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 (*Recorder) Frames ¶
Frames returns a copy of the captured frames in order. Convenience for tests that only care about the payload.
func (*Recorder) OnSubmit ¶
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.