File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
Sources/Services/ContainerSandboxService/Server
Tests/CLITests/Subcommands/Containers Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments