MCPcopy
hub / github.com/moby/moby / assertPortRange

Function assertPortRange

integration-cli/docker_cli_port_test.go:193–236  ·  view source on GitHub ↗
(ctx context.Context, id string, expectedTCP, expectedUDP []int)

Source from the content-addressed store, hash-verified

191}
192
193func assertPortRange(ctx context.Context, id string, expectedTCP, expectedUDP []int) error {
194 apiClient := testEnv.APIClient()
195 res, err := apiClient.ContainerInspect(ctx, id, client.ContainerInspectOptions{})
196 if err != nil {
197 return err
198 }
199
200 var validTCP, validUDP bool
201 for port, binding := range res.Container.NetworkSettings.Ports {
202 if port.Proto() == "tcp" && len(expectedTCP) == 0 {
203 continue
204 }
205 if port.Proto() == "udp" && len(expectedTCP) == 0 {
206 continue
207 }
208
209 for _, b := range binding {
210 port, err := strconv.Atoi(b.HostPort)
211 if err != nil {
212 return err
213 }
214
215 if len(expectedTCP) > 0 {
216 if port < expectedTCP[0] || port > expectedTCP[1] {
217 return fmt.Errorf("tcp port (%d) not in range expected range %d-%d", port, expectedTCP[0], expectedTCP[1])
218 }
219 validTCP = true
220 }
221 if len(expectedUDP) > 0 {
222 if port < expectedUDP[0] || port > expectedUDP[1] {
223 return fmt.Errorf("udp port (%d) not in range expected range %d-%d", port, expectedUDP[0], expectedUDP[1])
224 }
225 validUDP = true
226 }
227 }
228 }
229 if !validTCP {
230 return errors.New("tcp port not found")
231 }
232 if !validUDP {
233 return errors.New("udp port not found")
234 }
235 return nil
236}
237
238func stopRemoveContainer(id string, t *testing.T) {
239 cli.DockerCmd(t, "rm", "-f", id)

Callers 1

TestPortListMethod · 0.85

Calls 5

APIClientMethod · 0.80
ErrorfMethod · 0.80
ContainerInspectMethod · 0.65
NewMethod · 0.65
ProtoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…