(ctx context.Context, id string, expectedTCP, expectedUDP []int)
| 191 | } |
| 192 | |
| 193 | func 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 | |
| 238 | func stopRemoveContainer(id string, t *testing.T) { |
| 239 | cli.DockerCmd(t, "rm", "-f", id) |
no test coverage detected
searching dependent graphs…