40eefbf008
Signed-off-by: Antonio Navarro Perez <antnavper@gmail.com>
46 lines
843 B
Go
46 lines
843 B
Go
package iio
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var testData []byte = []byte("Hello World")
|
|
|
|
func TestReadData(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
br := bytes.NewReader(testData)
|
|
r, err := NewDiskTeeReader(br)
|
|
require.NoError(err)
|
|
|
|
toRead := make([]byte, 5)
|
|
|
|
n, err := r.ReadAt(toRead, 6)
|
|
require.NoError(err)
|
|
require.Equal(5, n)
|
|
require.Equal("World", string(toRead))
|
|
|
|
r.ReadAt(toRead, 0)
|
|
require.NoError(err)
|
|
require.Equal(5, n)
|
|
require.Equal("Hello", string(toRead))
|
|
}
|
|
|
|
func TestReadDataEOF(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
br := bytes.NewReader(testData)
|
|
r, err := NewDiskTeeReader(br)
|
|
require.NoError(err)
|
|
|
|
toRead := make([]byte, 6)
|
|
|
|
n, err := r.ReadAt(toRead, 6)
|
|
require.Equal(io.EOF, err)
|
|
require.Equal(5, n)
|
|
require.Equal("World\x00", string(toRead))
|
|
}
|