2026-01-30 03:15:10 +01:00
|
|
|
import OpenClawKit
|
2025-12-14 02:05:50 +00:00
|
|
|
import Network
|
|
|
|
|
import Testing
|
2026-01-30 03:15:10 +01:00
|
|
|
@testable import OpenClaw
|
2025-12-14 02:05:50 +00:00
|
|
|
|
2026-01-19 05:44:36 +00:00
|
|
|
@Suite struct GatewayEndpointIDTests {
|
2025-12-14 02:05:50 +00:00
|
|
|
@Test func stableIDForServiceDecodesAndNormalizesName() {
|
|
|
|
|
let endpoint = NWEndpoint.service(
|
2026-01-30 03:15:10 +01:00
|
|
|
name: "OpenClaw\\032Gateway \\032 Node\n",
|
|
|
|
|
type: "_openclaw-gw._tcp",
|
2025-12-14 02:05:50 +00:00
|
|
|
domain: "local.",
|
|
|
|
|
interface: nil)
|
|
|
|
|
|
2026-01-30 03:15:10 +01:00
|
|
|
#expect(GatewayEndpointID.stableID(endpoint) == "_openclaw-gw._tcp|local.|OpenClaw Gateway Node")
|
2025-12-14 02:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test func stableIDForNonServiceUsesEndpointDescription() {
|
|
|
|
|
let endpoint = NWEndpoint.hostPort(host: NWEndpoint.Host("127.0.0.1"), port: 4242)
|
2026-01-19 05:44:36 +00:00
|
|
|
#expect(GatewayEndpointID.stableID(endpoint) == String(describing: endpoint))
|
2025-12-14 02:05:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test func prettyDescriptionDecodesBonjourEscapes() {
|
|
|
|
|
let endpoint = NWEndpoint.service(
|
2026-01-30 03:15:10 +01:00
|
|
|
name: "OpenClaw\\032Gateway",
|
|
|
|
|
type: "_openclaw-gw._tcp",
|
2025-12-14 02:05:50 +00:00
|
|
|
domain: "local.",
|
|
|
|
|
interface: nil)
|
|
|
|
|
|
2026-01-19 05:44:36 +00:00
|
|
|
let pretty = GatewayEndpointID.prettyDescription(endpoint)
|
2025-12-14 02:05:50 +00:00
|
|
|
#expect(pretty == BonjourEscapes.decode(String(describing: endpoint)))
|
|
|
|
|
#expect(!pretty.localizedCaseInsensitiveContains("\\032"))
|
|
|
|
|
}
|
|
|
|
|
}
|