Skip to content

Commit 7018781

Browse files
committed
Initial commit
CR comment add CLI test inline implementation into SandboxService fix test
1 parent 4af1cc0 commit 7018781

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Sources/Services/ContainerSandboxService/Server/SandboxService.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,11 @@ public actor SandboxService {
849849
czConfig.sockets.append(socketConfig)
850850
}
851851

852-
czConfig.hostname = config.id
852+
let containerId = config.id
853+
czConfig.hostname =
854+
containerId.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true)
855+
.first
856+
.map { String($0) } ?? containerId
853857

854858
if let dns = config.dns {
855859
czConfig.dns = DNS(

Tests/CLITests/Subcommands/Containers/TestCLICreate.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,29 @@ class TestCLICreateCommand: CLITest {
9797
}
9898
}
9999

100+
@Test func testCreateWithFQDNName() throws {
101+
let name = "test.example.com"
102+
let expectedHostname = "test"
103+
#expect(throws: Never.self, "expected container create with FQDN name to succeed") {
104+
try doCreate(name: name, args: ["echo", "hello"])
105+
try doStart(name: name)
106+
defer {
107+
try? doStop(name: name)
108+
try? doRemove(name: name)
109+
}
110+
try waitForContainerRunning(name)
111+
let inspectResp = try inspectContainer(name)
112+
let attachmentHostname = inspectResp.networks.first?.hostname ?? ""
113+
let gotHostname =
114+
attachmentHostname
115+
.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true)
116+
.first
117+
.map { String($0) } ?? attachmentHostname
118+
#expect(
119+
gotHostname == expectedHostname,
120+
"expected hostname to be extracted as '\(expectedHostname)' from FQDN '\(name)', got '\(gotHostname)' (attachment hostname: '\(attachmentHostname)')"
121+
)
122+
}
123+
}
124+
100125
}

0 commit comments

Comments
 (0)