file-store/pkg/erasureencode/decode_test.go

144 lines
4.2 KiB
Go
Raw Normal View History

2022-08-24 02:54:01 +00:00
package erasureencode
import (
// "fmt"
"bytes"
"io"
"testing"
)
var simpleDecodeMeta = &EEMeta{
Params: Params{
Size: 0,
Stride: 2,
Shards: 3,
Parity: 2,
},
}
func TestDecode_EvenStride_Full(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c, 0x0d}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x0e, 0x0f}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x10, 0x11}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}
func TestDecode_EvenStride_Short1(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c, 0x0d}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x0e, 0x0f}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x10, 0x00}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}
func TestDecode_EvenStride_Short2(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c, 0x0d}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x0e, 0x0f}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x00, 0x00}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}
func TestDecode_OddStride_Full(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x0d}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x0e}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}
func TestDecode_OddStride_Short1(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x0d}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x00}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}
func TestDecode_OddStride_Short2(t *testing.T) {
expected := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c}
simpleDecodeMeta.Params.Size = int64(len(expected))
2022-08-24 02:54:01 +00:00
inputs := []io.ReadSeeker{
bytes.NewReader([]byte{0x00, 0x01, 0x06, 0x07, 0x0c}),
bytes.NewReader([]byte{0x02, 0x03, 0x08, 0x09, 0x00}),
bytes.NewReader([]byte{0x04, 0x05, 0x0a, 0x0b, 0x00}),
}
output := &bytes.Buffer{}
if err := Decode(inputs, output, simpleDecodeMeta); err != nil {
t.Errorf(`Error: %s`, err)
}
actual := output.Bytes()
if !bytes.Equal(actual, expected) {
t.Errorf(`Expected %x to equal %x`, actual, expected)
}
}