Files
AetherForge/server/internal/api/cloud_instance_meta_test.go
AetherForge bcd25b53a6
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fix server feature tests and refresh Go Test* counts.
Unskip cloud-map export assertions, correct cloud venue class fixtures, and update tests/README.md to 960 server / 670 agent Test* totals.
2026-06-07 11:11:30 -07:00

91 lines
2.7 KiB
Go

package api
import (
"encoding/json"
"testing"
"crypto-miner-server/internal/db"
"crypto-miner-server/internal/models"
)
func TestPrimarySeederScopePrefersVPC(t *testing.T) {
scope := primarySeederScope("10.1.2.3", CloudInstanceMeta{VpcID: "vpc-abc123"})
if scope != "vpc-abc123" {
t.Fatalf("scope=%q", scope)
}
scope = primarySeederScope("10.1.2.3", CloudInstanceMeta{})
if scope != "10.1.2" {
t.Fatalf("subnet scope=%q", scope)
}
}
func TestAgentMatchesPrimaryScopeVPC(t *testing.T) {
database, err := db.New(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.storeAgentCloudMeta("vpc-seed-a", CloudInstanceMeta{VpcID: "vpc-shared", Region: "us-east-1"})
hub.storeAgentCloudMeta("vpc-seed-b", CloudInstanceMeta{VpcID: "vpc-other"})
if !hub.agentMatchesPrimaryScopeLocked("vpc-seed-a", "vpc-shared") {
t.Fatal("expected vpc match")
}
if hub.agentMatchesPrimaryScopeLocked("vpc-seed-b", "vpc-shared") {
t.Fatal("expected vpc mismatch")
}
}
func TestAttachVPCSeederTelemetry(t *testing.T) {
database, err := db.New(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = database.Close() })
hub := NewWSHub(database)
hub.storeAgentCloudMeta("seed-vpc", CloudInstanceMeta{
VpcID: "vpc-99", SubnetID: "subnet-1", Region: "eu-west-1",
})
agent := &models.Agent{ID: "seed-vpc"}
hub.attachVPCSeederTelemetry(agent, "seed-vpc", "10.0.0.1", "seeder", "seed-vpc")
if agent.CloudVpcID != "vpc-99" || agent.CloudSubnetID != "subnet-1" || agent.CloudRegion != "eu-west-1" {
t.Fatalf("cloud fields=%+v", agent)
}
if agent.VPCPrimarySeeder == nil || !*agent.VPCPrimarySeeder {
t.Fatalf("primary=%v", agent.VPCPrimarySeeder)
}
}
func TestAuthFleetTorrentSeederHints(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{FleetRolesEnabled: true, FleetTorrentEnabled: true})
_ = database.UpsertAgent(&models.Agent{ID: "ec2-seed", Name: "seed", IP: "10.8.0.5", Status: "online"})
conn, _ := dialAgentWS(t, hub)
resp := authAgentConn(t, conn, map[string]interface{}{
"agent_id": "ec2-seed",
"hostname": "ec2-host",
"platform": "linux",
"version": "test",
"fleet_role": "seeder",
"seeder_mode": true,
})
var body map[string]interface{}
if err := json.Unmarshal(resp.Payload, &body); err != nil {
t.Fatal(err)
}
if body["fleet_torrent_enabled"] != true {
t.Fatalf("fleet_torrent_enabled=%#v", body["fleet_torrent_enabled"])
}
if _, ok := body["subnet_primary_seeder"].(string); !ok {
t.Fatalf("subnet_primary_seeder missing: %#v", body)
}
}