Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/storage: fix Seeker.Seek (#2854)
Seeker.Seek and Seeker.Read denote methods on different embedded interfaces, causing Seek to operate on a different offset than Read. Fix that by embedding an io.ReadSeeker.
- Loading branch information
Showing
4 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package storage | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSeeker(t *testing.T) { | ||
r := NewBytesReader([]byte{0, 1}) | ||
s, err := NewSeeker(r) | ||
require.NoError(t, err) | ||
|
||
// Test that ReadAt doesn't affect the offset. | ||
b := make([]byte, 3) | ||
n, err := s.ReadAt(b, 1) | ||
assert.ErrorIs(t, err, io.EOF) | ||
assert.Equal(t, 1, n) | ||
assert.EqualValues(t, 1, b[0]) | ||
n64, err := s.Seek(0, io.SeekCurrent) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 0, n64) | ||
|
||
// Test Read followed by Seek to the beginning. | ||
for i := 0; i < 3; i++ { | ||
n, err = s.Read(b) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 2, n) | ||
assert.EqualValues(t, 0, b[0]) | ||
assert.EqualValues(t, 1, b[1]) | ||
n64, err = s.Seek(0, io.SeekStart) | ||
assert.NoError(t, err) | ||
assert.EqualValues(t, 0, n64) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,4 @@ script: | | |
outputs: | ||
- name: stderr | ||
regexp: | | ||
.*: zst trailer not found | ||
.*: EOF |