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.
71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"crypto-miner-server/internal/db"
|
|
)
|
|
|
|
func TestAuthSpreadPolicyIncludesErasureLanes(t *testing.T) {
|
|
database, err := db.New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = database.Close() })
|
|
|
|
hub := NewWSHub(database)
|
|
hub.SetServerPolicy(ServerPolicy{ErasureLanesEnabled: true})
|
|
|
|
conn, _ := dialAgentWS(t, hub)
|
|
resp := authAgentConn(t, conn, map[string]interface{}{
|
|
"agent_id": "erasure-policy-agent",
|
|
"hostname": "host",
|
|
"platform": "windows",
|
|
"version": "test",
|
|
})
|
|
var body map[string]interface{}
|
|
if err := json.Unmarshal(resp.Payload, &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
raw, ok := body["spread_policy"]
|
|
if !ok {
|
|
t.Fatalf("spread_policy missing from auth_response: %#v", body)
|
|
}
|
|
policyBytes, _ := json.Marshal(raw)
|
|
var policy map[string]interface{}
|
|
if err := json.Unmarshal(policyBytes, &policy); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
enabled, ok := policy["erasure_lanes_enabled"].(bool)
|
|
if !ok || !enabled {
|
|
t.Fatalf("policy=%#v", policy)
|
|
}
|
|
}
|
|
|
|
func TestAuthSpreadPolicyOmitsErasureWhenDisabled(t *testing.T) {
|
|
database, err := db.New(t.TempDir())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { _ = database.Close() })
|
|
|
|
hub := NewWSHub(database)
|
|
hub.SetServerPolicy(ServerPolicy{})
|
|
|
|
conn, _ := dialAgentWS(t, hub)
|
|
resp := authAgentConn(t, conn, map[string]interface{}{
|
|
"agent_id": "no-erasure-agent",
|
|
"hostname": "host",
|
|
"platform": "windows",
|
|
"version": "test",
|
|
})
|
|
var body map[string]interface{}
|
|
if err := json.Unmarshal(resp.Payload, &body); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, ok := body["spread_policy"]; ok {
|
|
t.Fatalf("spread_policy should be omitted: %#v", body["spread_policy"])
|
|
}
|
|
}
|