Files
LINUX-AETHERFORGE/internal/erasure/erasure_test.go
drjones 3678b199d0
Some checks failed
Test / test (push) Has been cancelled
Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
2026-07-04 09:31:23 +00:00

59 lines
1.3 KiB
Go

package erasure
import (
"context"
"bytes"
"testing"
"forge-mesh/internal/db"
)
func TestEncodeReconstruct4Plus2(t *testing.T) {
conn, err := db.Open(t.TempDir() + "/test.db")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
svc := NewService(conn)
ctx := context.Background()
payload := []byte("forge-mesh erasure shard payload for T12 reassembly")
bundle, err := svc.Encode(ctx, "test-bundle", payload)
if err != nil {
t.Fatal(err)
}
if bundle.DataShards != 4 || bundle.ParityShards != 2 {
t.Fatalf("expected 4+2, got %d+%d", bundle.DataShards, bundle.ParityShards)
}
// Reconstruct with any 4 of 6 shards
rebuilt, err := svc.Reconstruct(ctx, bundle.ID, []int{0, 1, 2, 5})
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(payload, rebuilt) {
t.Fatalf("reconstruct mismatch: got %q want %q", rebuilt, payload)
}
}
func TestReconstructNeedsMinShards(t *testing.T) {
conn, err := db.Open(t.TempDir() + "/test.db")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
svc := NewService(conn)
ctx := context.Background()
bundle, err := svc.Encode(ctx, "small", []byte("x"))
if err != nil {
t.Fatal(err)
}
_, err = svc.Reconstruct(ctx, bundle.ID, []int{0, 1, 2})
if err == nil {
t.Fatal("expected error when fewer than 4 shards provided")
}
}