mirror of https://github.com/docker/cli.git
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:
parent
58487e088a
commit
c5613ac032
|
@ -15,18 +15,27 @@ func TestNewPortCommandOutput(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
ips []string
|
ips []string
|
||||||
|
port string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "container-port-ipv4",
|
name: "container-port-ipv4",
|
||||||
ips: []string{"0.0.0.0"},
|
ips: []string{"0.0.0.0"},
|
||||||
|
port: "80",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "container-port-ipv6",
|
name: "container-port-ipv6",
|
||||||
ips: []string{"::"},
|
ips: []string{"::"},
|
||||||
|
port: "80",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "container-port-ipv6-and-ipv4",
|
name: "container-port-ipv6-and-ipv4",
|
||||||
ips: []string{"::", "0.0.0.0"},
|
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 {
|
for _, tc := range testCases {
|
||||||
|
@ -37,18 +46,26 @@ func TestNewPortCommandOutput(t *testing.T) {
|
||||||
ci := types.ContainerJSON{NetworkSettings: &types.NetworkSettings{}}
|
ci := types.ContainerJSON{NetworkSettings: &types.NetworkSettings{}}
|
||||||
ci.NetworkSettings.Ports = nat.PortMap{
|
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 {
|
for i, ip := range tc.ips {
|
||||||
ci.NetworkSettings.Ports["80/tcp"][i] = nat.PortBinding{
|
ci.NetworkSettings.Ports["80/tcp"][i] = nat.PortBinding{
|
||||||
HostIP: ip, HostPort: "3456",
|
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
|
return ci, nil
|
||||||
},
|
},
|
||||||
}, test.EnableContentTrust)
|
}, test.EnableContentTrust)
|
||||||
cmd := NewPortCommand(cli)
|
cmd := NewPortCommand(cli)
|
||||||
cmd.SetErr(io.Discard)
|
cmd.SetErr(io.Discard)
|
||||||
cmd.SetArgs([]string{"some_container", "80"})
|
cmd.SetArgs([]string{"some_container", tc.port})
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
golden.Assert(t, cli.OutBuffer().String(), tc.name+".golden")
|
golden.Assert(t, cli.OutBuffer().String(), tc.name+".golden")
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
[::]:5678
|
||||||
|
0.0.0.0:5678
|
Loading…
Reference in New Issue