package api import ( "encoding/json" "os" "path/filepath" "testing" "crypto-miner-server/internal/spreadrouter" ) func TestAttachCloudMapRouteVia(t *testing.T) { dir := t.TempDir() cfg := map[string]interface{}{ "server": map[string]interface{}{ "cloud_map_namespace": "prod.local", "cloud_map_service": "seeder", }, } data, _ := json.Marshal(cfg) if err := os.WriteFile(filepath.Join(dir, "config.json"), data, 0o644); err != nil { t.Fatal(err) } h := &DeployPlanHandler{dataDir: dir} body := DeployPlanBody{} h.attachCloudMapRouteVia(&body) if body.SpreadRouteHint == nil || body.SpreadRouteHint.RouteVia != "seeder.svc.prod.local" { t.Fatalf("hint=%+v", body.SpreadRouteHint) } } func TestAttachCloudMapRouteViaPreservesExisting(t *testing.T) { dir := t.TempDir() h := &DeployPlanHandler{dataDir: dir} body := DeployPlanBody{ SpreadRouteHint: &spreadrouter.SpreadRouteHint{RouteVia: "custom.svc.lab.local"}, } h.attachCloudMapRouteVia(&body) if body.SpreadRouteHint.RouteVia != "custom.svc.lab.local" { t.Fatalf("route_via=%q", body.SpreadRouteHint.RouteVia) } }