MCPcopy
hub / github.com/grafana/tempo / TestBufferedReaderInvalidatesBufferOnErr

Function TestBufferedReaderInvalidatesBufferOnErr

pkg/io/buffered_test.go:153–183  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

151}
152
153func TestBufferedReaderInvalidatesBufferOnErr(t *testing.T) {
154 erroringReaderAt := &erroringReaderAt{
155 err: nil,
156 }
157
158 r := NewBufferedReaderAt(erroringReaderAt, 100, 50, 1)
159
160 // force the reader to return an error
161 erroringReaderAt.err = errors.New("error")
162 actual := make([]byte, 10)
163 read, err := r.ReadAt(actual, 0)
164 require.Error(t, err)
165 require.Equal(t, 0, read)
166 require.Equal(t, []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, actual) // first 10 bytes should be zeroed
167
168 // clear the error and read the first 10 bytes again
169 erroringReaderAt.err = nil
170 actual = make([]byte, 10)
171 read, err = r.ReadAt(actual, 0)
172 require.NoError(t, err)
173 require.Equal(t, 10, read)
174 require.Equal(t, []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, actual) // first 10 bytes should be read
175
176 // force the reader to return io.EOF and see it handled correctly
177 erroringReaderAt.err = io.EOF
178 actual = make([]byte, 10)
179 read, err = r.ReadAt(actual, 90)
180 require.ErrorIs(t, err, io.EOF)
181 require.Equal(t, 10, read)
182 require.Equal(t, []byte{90, 91, 92, 93, 94, 95, 96, 97, 98, 99}, actual) // last 10 bytes should be read
183}

Callers

nothing calls this directly

Calls 4

ReadAtMethod · 0.95
NewBufferedReaderAtFunction · 0.85
ErrorMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected