Skip to content

Commit

Permalink
pkg/ioutils: remove unused NewReaderErrWrapper
Browse files Browse the repository at this point in the history
It was added in Docker [v1.3.0] through bd130e7,
but never used, and its behavior never documented. There are no publicly
visible external consumers  of this function, so let's remove it.

[v1.3.0]: https://github.com/moby/moby/releases/tag/v1.3.0

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Jan 10, 2025
1 parent d34a5f5 commit e26122c
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 51 deletions.
21 changes: 0 additions & 21 deletions pkg/ioutils/readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,6 @@ func NewReadCloserWrapper(r io.Reader, closer func() error) io.ReadCloser {
}
}

type readerErrWrapper struct {
reader io.Reader
closer func()
}

func (r *readerErrWrapper) Read(p []byte) (int, error) {
n, err := r.reader.Read(p)
if err != nil {
r.closer()
}
return n, err
}

// NewReaderErrWrapper returns a new io.Reader.
func NewReaderErrWrapper(r io.Reader, closer func()) io.Reader {
return &readerErrWrapper{
reader: r,
closer: closer,
}
}

// cancelReadCloser wraps an io.ReadCloser with a context for cancelling read
// operations.
type cancelReadCloser struct {
Expand Down
30 changes: 0 additions & 30 deletions pkg/ioutils/readers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"strings"
"testing"
"testing/iotest"
"time"
)

Expand All @@ -31,35 +30,6 @@ func TestReadCloserWrapperClose(t *testing.T) {
}
}

func TestReaderErrWrapperReadOnError(t *testing.T) {
called := false
expectedErr := errors.New("error reader always fail")
wrapper := NewReaderErrWrapper(iotest.ErrReader(expectedErr), func() {
called = true
})
_, err := wrapper.Read([]byte{})
if !errors.Is(err, expectedErr) {
t.Errorf("expected %v, got: %v", expectedErr, err)
}
if !called {
t.Fatalf("readErrWrapper should have called the anonymous function on failure")
}
}

func TestReaderErrWrapperRead(t *testing.T) {
const text = "hello world"
wrapper := NewReaderErrWrapper(strings.NewReader(text), func() {
t.Fatalf("readErrWrapper should not have called the anonymous function")
})
num, err := wrapper.Read(make([]byte, len(text)+10))
if err != nil {
t.Error(err)
}
if expected := len(text); num != expected {
t.Errorf("readerErrWrapper should have read %d byte, but read %d", expected, num)
}
}

type perpetualReader struct{}

func (p *perpetualReader) Read(buf []byte) (n int, err error) {
Expand Down

0 comments on commit e26122c

Please sign in to comment.