Merge pull request #5468 from akerouanton/fix-ps-ipv6

cli/formatter: fix unbracketed IPv6 addrs
This commit is contained in:
Sebastiaan van Stijn 2024-09-23 15:31:02 +02:00 committed by GitHub
commit 9d478be4a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 61 additions and 2 deletions

View File

@ -377,7 +377,7 @@ func formGroup(key string, start, last uint16) string {
group = fmt.Sprintf("%s-%d", group, last)
}
if ip != "" {
group = fmt.Sprintf("%s:%s->%s", ip, group, group)
group = fmt.Sprintf("%s->%s", net.JoinHostPort(ip, group), group)
}
return group + "/" + groupType
}

View File

@ -589,6 +589,17 @@ func TestDisplayablePorts(t *testing.T) {
},
expected: "4.3.2.1:8899->9988/tcp",
},
{
ports: []container.Port{
{
IP: "::1",
PrivatePort: 9988,
PublicPort: 8899,
Type: "tcp",
},
},
expected: "[::1]:8899->9988/tcp",
},
{
ports: []container.Port{
{
@ -600,6 +611,17 @@ func TestDisplayablePorts(t *testing.T) {
},
expected: "4.3.2.1:9988->9988/tcp",
},
{
ports: []container.Port{
{
IP: "::1",
PrivatePort: 9988,
PublicPort: 9988,
Type: "tcp",
},
},
expected: "[::1]:9988->9988/tcp",
},
{
ports: []container.Port{
{
@ -628,6 +650,22 @@ func TestDisplayablePorts(t *testing.T) {
},
expected: "1.2.3.4:9998-9999->9998-9999/udp",
},
{
ports: []container.Port{
{
IP: "::1",
PublicPort: 9998,
PrivatePort: 9998,
Type: "udp",
}, {
IP: "::1",
PublicPort: 9999,
PrivatePort: 9999,
Type: "udp",
},
},
expected: "[::1]:9998-9999->9998-9999/udp",
},
{
ports: []container.Port{
{
@ -644,6 +682,22 @@ func TestDisplayablePorts(t *testing.T) {
},
expected: "1.2.3.4:8887->9998/udp, 1.2.3.4:8888->9999/udp",
},
{
ports: []container.Port{
{
IP: "::1",
PublicPort: 8887,
PrivatePort: 9998,
Type: "udp",
}, {
IP: "::1",
PublicPort: 8888,
PrivatePort: 9999,
Type: "udp",
},
},
expected: "[::1]:8887->9998/udp, [::1]:8888->9999/udp",
},
{
ports: []container.Port{
{
@ -688,9 +742,14 @@ func TestDisplayablePorts(t *testing.T) {
PrivatePort: 2233,
PublicPort: 3322,
Type: "tcp",
}, {
IP: "::1",
PrivatePort: 2233,
PublicPort: 3322,
Type: "tcp",
},
},
expected: "4.3.2.1:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
expected: "4.3.2.1:3322->2233/tcp, [::1]:3322->2233/tcp, 1.2.3.4:8899->9988/tcp, 1.2.3.4:8899->9988/udp",
},
{
ports: []container.Port{