cli/command/container: TestNewPortCommandOutput improve test

Make sure that the container has multiple port-mappings to illustrate
that only the given port is matched.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-12-01 10:47:10 +01:00
parent 58487e088a
commit c5613ac032
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
2 changed files with 21 additions and 2 deletions

View File

@ -15,18 +15,27 @@ func TestNewPortCommandOutput(t *testing.T) {
testCases := []struct {
name string
ips []string
port string
}{
{
name: "container-port-ipv4",
ips: []string{"0.0.0.0"},
port: "80",
},
{
name: "container-port-ipv6",
ips: []string{"::"},
port: "80",
},
{
name: "container-port-ipv6-and-ipv4",
ips: []string{"::", "0.0.0.0"},
port: "80",
},
{
name: "container-port-ipv6-and-ipv4-443-udp",
ips: []string{"::", "0.0.0.0"},
port: "443/udp",
},
}
for _, tc := range testCases {
@ -36,19 +45,27 @@ func TestNewPortCommandOutput(t *testing.T) {
inspectFunc: func(string) (types.ContainerJSON, error) {
ci := types.ContainerJSON{NetworkSettings: &types.NetworkSettings{}}
ci.NetworkSettings.Ports = nat.PortMap{
"80/tcp": make([]nat.PortBinding, len(tc.ips)),
"80/tcp": make([]nat.PortBinding, len(tc.ips)),
"443/tcp": make([]nat.PortBinding, len(tc.ips)),
"443/udp": make([]nat.PortBinding, len(tc.ips)),
}
for i, ip := range tc.ips {
ci.NetworkSettings.Ports["80/tcp"][i] = nat.PortBinding{
HostIP: ip, HostPort: "3456",
}
ci.NetworkSettings.Ports["443/tcp"][i] = nat.PortBinding{
HostIP: ip, HostPort: "4567",
}
ci.NetworkSettings.Ports["443/udp"][i] = nat.PortBinding{
HostIP: ip, HostPort: "5678",
}
}
return ci, nil
},
}, test.EnableContentTrust)
cmd := NewPortCommand(cli)
cmd.SetErr(io.Discard)
cmd.SetArgs([]string{"some_container", "80"})
cmd.SetArgs([]string{"some_container", tc.port})
err := cmd.Execute()
assert.NilError(t, err)
golden.Assert(t, cli.OutBuffer().String(), tc.name+".golden")

View File

@ -0,0 +1,2 @@
[::]:5678
0.0.0.0:5678