-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update golangci-lint Signed-off-by: Michael Crenshaw <[email protected]>
- Loading branch information
1 parent
0d74b68
commit e19c351
Showing
3 changed files
with
73 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
package io | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"io" | ||
"testing" | ||
) | ||
|
||
func TestByteReadSeeker_Read(t *testing.T) { | ||
inString := "hello world" | ||
reader := NewByteReadSeeker([]byte(inString)) | ||
var bytes = make([]byte, 11) | ||
n, err := reader.Read(bytes) | ||
require.NoError(t, err) | ||
assert.Equal(t, len(inString), n) | ||
assert.Equal(t, inString, string(bytes)) | ||
_, err = reader.Read(bytes) | ||
assert.ErrorIs(t, err, io.EOF) | ||
} | ||
|
||
func TestByteReadSeeker_Seek_Start(t *testing.T) { | ||
inString := "hello world" | ||
reader := NewByteReadSeeker([]byte(inString)) | ||
offset, err := reader.Seek(6, io.SeekStart) | ||
require.NoError(t, err) | ||
assert.Equal(t, int64(6), offset) | ||
var bytes = make([]byte, 5) | ||
n, err := reader.Read(bytes) | ||
require.NoError(t, err) | ||
assert.Equal(t, 5, n) | ||
assert.Equal(t, "world", string(bytes)) | ||
} | ||
|
||
func TestByteReadSeeker_Seek_Current(t *testing.T) { | ||
inString := "hello world" | ||
reader := NewByteReadSeeker([]byte(inString)) | ||
offset, err := reader.Seek(3, io.SeekCurrent) | ||
require.NoError(t, err) | ||
assert.Equal(t, int64(3), offset) | ||
offset, err = reader.Seek(3, io.SeekCurrent) | ||
require.NoError(t, err) | ||
assert.Equal(t, int64(6), offset) | ||
var bytes = make([]byte, 5) | ||
n, err := reader.Read(bytes) | ||
require.NoError(t, err) | ||
assert.Equal(t, 5, n) | ||
assert.Equal(t, "world", string(bytes)) | ||
} | ||
|
||
func TestByteReadSeeker_Seek_End(t *testing.T) { | ||
inString := "hello world" | ||
reader := NewByteReadSeeker([]byte(inString)) | ||
offset, err := reader.Seek(-5, io.SeekEnd) | ||
require.NoError(t, err) | ||
assert.Equal(t, int64(6), offset) | ||
var bytes = make([]byte, 5) | ||
n, err := reader.Read(bytes) | ||
require.NoError(t, err) | ||
assert.Equal(t, 5, n) | ||
assert.Equal(t, "world", string(bytes)) | ||
} | ||
|
||
func TestByteReadSeeker_Seek_OutOfBounds(t *testing.T) { | ||
inString := "hello world" | ||
reader := NewByteReadSeeker([]byte(inString)) | ||
_, err := reader.Seek(12, io.SeekStart) | ||
assert.Error(t, err) | ||
_, err = reader.Seek(-1, io.SeekStart) | ||
assert.Error(t, err) | ||
} |