func (l *testListener) Receive(msg Message) error {
	l.messages = append(l.messages, &msg)
	if len(l.messages) == l.wantMessages {
		close(l.done)
	}
	if len(l.messages) == l.wantMessages+1 {
		close(l.overflow)
	}
	if l.errorAfter > 0 && len(l.messages) > l.errorAfter {
		return fmt.Errorf("Too many messages")
	}
	return nil
}
Receive a Message, store it in the messages slice, close applicable channels, and return an error
if instructed
package msghub
import (
	"context"
	"fmt"
	"testing"
	"time"
)
type testListener struct {
	messages     []*Message  
	wantMessages int         
	errorAfter   int         
	done     chan struct{}  
	overflow chan struct{}  
}
func newTestListener(want int) *testListener {
	l := &testListener{
		messages:     make([]*Message, 0, want*2),
		wantMessages: want,
		done:         make(chan struct{}),
		overflow:     make(chan struct{}),
	}
	if want == 0 {
		close(l.done)
	}
	return l
}