package api import ( "bytes" "encoding/json" "net/http" "net/http/httptest" "strings" "testing" "crypto-miner-server/internal/cloudmap" ) func TestCloudTemplatePathsCloudMap(t *testing.T) { subdir, zip, err := cloudTemplatePaths("cloud-map") if err != nil || subdir != "cloud-map" || zip != "aetherforge-cloud-map.zip" { t.Fatalf("subdir=%q zip=%q err=%v", subdir, zip, err) } } func TestExportCloudMapTemplateZIP(t *testing.T) { root := integrationWorkspaceRoot(t) h := NewSpreadHandler(nil, t.TempDir(), root, nil) body, _ := json.Marshal(map[string]interface{}{ "template": "cloud-map", "server_url": "https://deck.example", "build_id": "pin-map", "campaign": "map-wave", "namespace_name": "aether.local", "region": "us-east-1", }) req := httptest.NewRequest(http.MethodPost, "/api/v1/builder/cloud-template-export", bytes.NewReader(body)) rec := httptest.NewRecorder() h.ExportCloudTemplate(rec, req) if rec.Code != http.StatusOK { t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String()) } entries := readZipEntries(t, rec.Body.Bytes()) if !strings.Contains(entries["service-registry.json"], "aetherforge-seeder") { t.Fatalf("service-registry.json=%s", entries["service-registry.json"]) } } func TestCloudMapKnowNodeTargetsFromRegistry(t *testing.T) { doc := cloudmap.RegistryDocument{ Namespace: "prod.local", Service: "seeder", Instances: []cloudmap.RegistryInstance{ {AgentID: "agent-a", Healthy: true}, {DNSName: "seeder.svc.prod.local", Healthy: true}, }, } targets := cloudmap.KnowNodeTargets(doc) if len(targets) != 2 || targets[0] != "agent-a" { t.Fatalf("targets=%v", targets) } }