diff --git a/revid/senders_test.go b/revid/senders_test.go index 1c516e16..360e540e 100644 --- a/revid/senders_test.go +++ b/revid/senders_test.go @@ -270,6 +270,8 @@ func TestNewMultiSender(t *testing.T) { } } +// dummyLoadSender is a loadSender implementation that allows us to simulate +// the behaviour of a loadSender and check that it performas as expected. type dummyLoadSender struct { data []byte buf [][]byte @@ -277,15 +279,20 @@ type dummyLoadSender struct { failHandled bool } +// newDummyLoadSender returns a pointer to a new dummyLoadSender. func newDummyLoadSender(fail bool) *dummyLoadSender { return &dummyLoadSender{failOnSend: fail, failHandled: true} } +// load takes a byte slice and assigns it to the dummyLoadSenders data slice. func (s *dummyLoadSender) load(d []byte) error { s.data = d return nil } +// send will append to dummyLoadSender's buf slice, only if failOnSend is false. +// If failOnSend is set to true, we expect that data sent won't be written to +// the buf simulating a failed send. func (s *dummyLoadSender) send() error { if !s.failOnSend { s.buf = append(s.buf, s.data) @@ -294,17 +301,23 @@ func (s *dummyLoadSender) send() error { return errSendFailed } +// release sets dummyLoadSender's data slice to nil. data can be checked to see +// if release has been called at the right time. func (s *dummyLoadSender) release() { s.data = nil } func (s *dummyLoadSender) close() error { return nil } +// handleSendFail simply sets the failHandled flag to true. This can be checked +// to see if handleSendFail has been called by the multiSender at the right time. func (s *dummyLoadSender) handleSendFail(err error) error { s.failHandled = true return nil } +// TestMultiSenderWrite checks that we can do basic writing to multiple senders +// using the multiSender. func TestMultiSenderWrite(t *testing.T) { senders := []loadSender{ newDummyLoadSender(false),