MCPcopy Index your code
hub / github.com/docker/cli / TestNewPortCommandOutput

Function TestNewPortCommandOutput

cli/command/container/port_test.go:16–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNewPortCommandOutput(t *testing.T) {
17 testCases := []struct {
18 name string
19 ips []netip.Addr
20 port string
21 }{
22 {
23 name: "container-port-ipv4",
24 ips: []netip.Addr{netip.MustParseAddr("0.0.0.0")},
25 port: "80",
26 },
27 {
28 name: "container-port-ipv6",
29 ips: []netip.Addr{netip.MustParseAddr("::")},
30 port: "80",
31 },
32 {
33 name: "container-port-ipv6-and-ipv4",
34 ips: []netip.Addr{netip.MustParseAddr("::"), netip.MustParseAddr("0.0.0.0")},
35 port: "80",
36 },
37 {
38 name: "container-port-ipv6-and-ipv4-443-udp",
39 ips: []netip.Addr{netip.MustParseAddr("::"), netip.MustParseAddr("0.0.0.0")},
40 port: "443/udp",
41 },
42 {
43 name: "container-port-all-ports",
44 ips: []netip.Addr{netip.MustParseAddr("::"), netip.MustParseAddr("0.0.0.0")},
45 },
46 }
47 for _, tc := range testCases {
48 t.Run(tc.name, func(t *testing.T) {
49 cli := test.NewFakeCli(&fakeClient{
50 inspectFunc: func(string) (client.ContainerInspectResult, error) {
51 ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}}
52 ci.NetworkSettings.Ports = network.PortMap{
53 network.MustParsePort("80/tcp"): make([]network.PortBinding, len(tc.ips)),
54 network.MustParsePort("443/tcp"): make([]network.PortBinding, len(tc.ips)),
55 network.MustParsePort("443/udp"): make([]network.PortBinding, len(tc.ips)),
56 }
57 for i, ip := range tc.ips {
58 ci.NetworkSettings.Ports[network.MustParsePort("80/tcp")][i] = network.PortBinding{
59 HostIP: ip, HostPort: "3456",
60 }
61 ci.NetworkSettings.Ports[network.MustParsePort("443/tcp")][i] = network.PortBinding{
62 HostIP: ip, HostPort: "4567",
63 }
64 ci.NetworkSettings.Ports[network.MustParsePort("443/udp")][i] = network.PortBinding{
65 HostIP: ip, HostPort: "5678",
66 }
67 }
68 return client.ContainerInspectResult{Container: ci}, nil
69 },
70 })
71 cmd := newPortCommand(cli)
72 cmd.SetErr(io.Discard)
73 cmd.SetArgs([]string{"some_container", tc.port})

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
newPortCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…