lotus/storage/sealer/fr32/readers_test.go

37 lines
756 B
Go
Raw Normal View History

2020-05-29 17:06:44 +00:00
package fr32_test
2020-05-28 22:17:23 +00:00
import (
2021-03-10 09:32:22 +00:00
"bufio"
2020-05-28 22:17:23 +00:00
"bytes"
"io"
2020-05-28 22:17:23 +00:00
"testing"
"github.com/stretchr/testify/require"
2020-09-07 03:49:10 +00:00
"github.com/filecoin-project/go-state-types/abi"
2020-05-29 17:06:44 +00:00
"github.com/filecoin-project/lotus/storage/sealer/fr32"
2020-05-28 22:17:23 +00:00
)
func TestUnpadReader(t *testing.T) {
ps := abi.PaddedPieceSize(64 << 20).Unpadded()
raw := bytes.Repeat([]byte{0x77}, int(ps))
padOut := make([]byte, ps.Padded())
fr32.Pad(raw, padOut)
2020-05-28 22:17:23 +00:00
r, err := fr32.NewUnpadReader(bytes.NewReader(padOut), ps.Padded())
2020-05-28 22:17:23 +00:00
if err != nil {
t.Fatal(err)
}
2021-03-10 09:32:22 +00:00
// using bufio reader to make sure reads are big enough for the padreader - it can't handle small reads right now
readered, err := io.ReadAll(bufio.NewReaderSize(r, 512))
2020-05-28 22:17:23 +00:00
if err != nil {
t.Fatal(err)
}
require.Equal(t, raw, readered)
}