package vpnruntime import "testing" func TestFabricServiceStreamRegistryTracksTunnelScopedStreams(t *testing.T) { registry := NewFabricServiceStreamRegistry() stream := registry.Register(FabricServiceStream{ TunnelID: "tunnel-1", ServiceID: "svc-1", StreamID: 42, TrafficClass: FabricServiceTrafficInteractive, Direction: FabricDirectionClientToGateway, ServiceTunnel: FabricServiceTunnel{ TunnelID: "tunnel-1", PoolID: "pool-vpn", ServiceID: "svc-1", ServiceKind: "ipv4-tunnel", }, Metadata: map[string]string{"adapter": "vpn"}, }) if stream.State != FabricServiceStreamStateOpen { t.Fatalf("stream state = %q, want open", stream.State) } if stream.ServiceTunnel.TransportOwner != DefaultFabricTransportOwner { t.Fatalf("service tunnel should remain fabric-owned: %+v", stream.ServiceTunnel) } streams := registry.StreamsForTunnel("tunnel-1") if len(streams) != 1 || streams[0].StreamID != 42 || streams[0].ServiceID != "svc-1" { t.Fatalf("streams for tunnel = %+v", streams) } registry.MarkClosed("tunnel-1", 42) streams = registry.StreamsForTunnel("tunnel-1") if len(streams) != 1 || streams[0].State != FabricServiceStreamStateClosed { t.Fatalf("closed stream not tracked: %+v", streams) } snapshot := registry.Snapshot() if snapshot["schema_version"] != FabricServiceStreamRegistrySchemaVersion || snapshot["stream_count"] != 1 || snapshot["open_count"] != 0 { t.Fatalf("unexpected registry snapshot: %+v", snapshot) } }