(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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}) |
nothing calls this directly
no test coverage detected
searching dependent graphs…