2020-05-29 17:06:44 +00:00
|
|
|
package fr32_test
|
2020-05-28 22:17:23 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-05-29 17:06:44 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/sector-storage/fr32"
|
2020-05-28 22:17:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestPadReader(t *testing.T) {
|
|
|
|
ps := abi.PaddedPieceSize(64 << 20).Unpadded()
|
|
|
|
|
|
|
|
raw := bytes.Repeat([]byte{0x55}, int(ps))
|
|
|
|
|
2020-05-29 17:06:44 +00:00
|
|
|
r, err := fr32.NewPadReader(bytes.NewReader(raw), ps)
|
2020-05-28 22:17:23 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
readerPadded, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
padOut := make([]byte, ps.Padded())
|
2020-05-29 17:06:44 +00:00
|
|
|
fr32.Pad(raw, padOut)
|
2020-05-28 22:17:23 +00:00
|
|
|
|
|
|
|
require.Equal(t, padOut, readerPadded)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnpadReader(t *testing.T) {
|
|
|
|
ps := abi.PaddedPieceSize(64 << 20).Unpadded()
|
|
|
|
|
|
|
|
raw := bytes.Repeat([]byte{0x77}, int(ps))
|
|
|
|
|
|
|
|
padOut := make([]byte, ps.Padded())
|
2020-05-29 17:06:44 +00:00
|
|
|
fr32.Pad(raw, padOut)
|
2020-05-28 22:17:23 +00:00
|
|
|
|
2020-05-29 17:06:44 +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)
|
|
|
|
}
|
|
|
|
|
|
|
|
readered, err := ioutil.ReadAll(r)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
require.Equal(t, raw, readered)
|
|
|
|
}
|