Initial commit: AetherForge Linux (forge-mesh) v0.1.0-dev
Some checks failed
Test / test (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
This commit is contained in:
58
internal/erasure/erasure_test.go
Normal file
58
internal/erasure/erasure_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user