From ab5fdf4f7e580ad7fe4664f74bec4d13ddc0d04d Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Wed, 21 Aug 2024 16:34:16 +0200 Subject: [PATCH] renamed ChannelReadWriter to ChannelReadWriteCloser. --- pkg/testsupport/channelreadwriter.go | 16 ++++++++-------- pkg/testsupport/channelreadwriter_test.go | 6 +++--- pkg/testsupport/inmemoryconnection.go | 8 ++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/testsupport/channelreadwriter.go b/pkg/testsupport/channelreadwriter.go index f979f76..5cf5c78 100644 --- a/pkg/testsupport/channelreadwriter.go +++ b/pkg/testsupport/channelreadwriter.go @@ -9,7 +9,7 @@ import ( "sync" ) -type ChannelReadWriter struct { +type ChannelReadWriteCloser struct { ctx context.Context receiverMutex sync.Mutex @@ -22,9 +22,9 @@ type ChannelReadWriter struct { closed bool } -func NewChannelReadWriter(ctx context.Context, receiver <-chan []byte, - sender chan<- []byte) *ChannelReadWriter { - return &ChannelReadWriter{ +func NewChannelReadWriteCloser(ctx context.Context, receiver <-chan []byte, + sender chan<- []byte) *ChannelReadWriteCloser { + return &ChannelReadWriteCloser{ ctx: ctx, receiverMutex: sync.Mutex{}, receiver: receiver, @@ -34,7 +34,7 @@ func NewChannelReadWriter(ctx context.Context, receiver <-chan []byte, } } -func (rw *ChannelReadWriter) Read(p []byte) (n int, err error) { +func (rw *ChannelReadWriteCloser) Read(p []byte) (n int, err error) { rw.receiverMutex.Lock() defer rw.receiverMutex.Unlock() @@ -57,7 +57,7 @@ func (rw *ChannelReadWriter) Read(p []byte) (n int, err error) { } } -func (rw *ChannelReadWriter) Write(pIn []byte) (n int, err error) { +func (rw *ChannelReadWriteCloser) Write(pIn []byte) (n int, err error) { p := make([]byte, len(pIn), len(pIn)) copy(p, pIn) rw.senderMutex.Lock() @@ -85,12 +85,12 @@ func (rw *ChannelReadWriter) Write(pIn []byte) (n int, err error) { return len(p), nil } -func (rw *ChannelReadWriter) Close() error { +func (rw *ChannelReadWriteCloser) Close() error { rw.senderMutex.Lock() defer rw.senderMutex.Unlock() if !rw.closed { - log.Println("Closing ChannelReadWriter") + log.Println("Closing ChannelReadWriteCloser") buf := make([]byte, 0) runtime.Stack(buf, false) log.Printf("Stack %v", string(buf)) diff --git a/pkg/testsupport/channelreadwriter_test.go b/pkg/testsupport/channelreadwriter_test.go index fca43af..b666f20 100644 --- a/pkg/testsupport/channelreadwriter_test.go +++ b/pkg/testsupport/channelreadwriter_test.go @@ -19,7 +19,7 @@ type ChannelReadWriterTestSuite struct { cancelFunc context.CancelFunc toChannel chan<- []byte fromChannel <-chan []byte - conn *ChannelReadWriter + conn *ChannelReadWriteCloser } func TestChannelReadWriterSuite(t *testing.T) { @@ -36,7 +36,7 @@ func (s *ChannelReadWriterTestSuite) createChannel() { ctx, cancelFunc := CreateTestContext(context.Background(), 10*time.Second) s.ctx = ctx s.cancelFunc = cancelFunc - s.conn = NewChannelReadWriter(ctx, toChannel, fromChannel) + s.conn = NewChannelReadWriteCloser(ctx, toChannel, fromChannel) } func (s *ChannelReadWriterTestSuite) SetupSuite() { @@ -83,7 +83,7 @@ func (s *ChannelReadWriterTestSuite) Test_SuccessfulChannelToReadWriter() { }, { // NOTE: no intelligence in the reader to fill up the read buffer when it is not full // therefore, the second read will have only 1 char since the first channel read returned - // 3 of which 2 where returned in the first read call to the ChannelReadWriter. + // 3 of which 2 where returned in the first read call to the ChannelReadWriteCloser. name: "buffer_too_small_multiple_writes", data: []string{"hel", "lo"}, chunkSizes: []int{2, 2, 2}, diff --git a/pkg/testsupport/inmemoryconnection.go b/pkg/testsupport/inmemoryconnection.go index c445bb8..3673e03 100644 --- a/pkg/testsupport/inmemoryconnection.go +++ b/pkg/testsupport/inmemoryconnection.go @@ -20,14 +20,14 @@ func NewInmemoryConnection(ctx context.Context, addr string, channelSize int) *I return &pipe } -func (bitpipe *InmemoryConnection) Front() *ChannelReadWriter { +func (bitpipe *InmemoryConnection) Front() *ChannelReadWriteCloser { return pipe(bitpipe.ctx, bitpipe.backToFront, bitpipe.frontToBack, bitpipe.addr) } -func (bitpipe *InmemoryConnection) Back() *ChannelReadWriter { +func (bitpipe *InmemoryConnection) Back() *ChannelReadWriteCloser { return pipe(bitpipe.ctx, bitpipe.frontToBack, bitpipe.backToFront, bitpipe.addr) } -func pipe(ctx context.Context, receiveBuffer <-chan []byte, sendBuffer chan<- []byte, remoteAddr string) *ChannelReadWriter { - return NewChannelReadWriter(ctx, receiveBuffer, sendBuffer) +func pipe(ctx context.Context, receiveBuffer <-chan []byte, sendBuffer chan<- []byte, remoteAddr string) *ChannelReadWriteCloser { + return NewChannelReadWriteCloser(ctx, receiveBuffer, sendBuffer) }