@@ -4,13 +4,15 @@ import (
44 "errors"
55 "fmt"
66 "io"
7+ "net/netip"
78 "os"
89 "runtime"
910 "strings"
1011 "testing"
1112 "time"
1213
1314 "github.com/moby/moby/api/types/container"
15+ "github.com/moby/moby/api/types/network"
1416 networktypes "github.com/moby/moby/api/types/network"
1517 "github.com/spf13/pflag"
1618 "gotest.tools/v3/assert"
@@ -438,12 +440,12 @@ func TestParseWithExpose(t *testing.T) {
438440 "8080-NaN/tcp" : `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax` ,
439441 "1234567890-8080/tcp" : `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range` ,
440442 }
441- valids := map [string ][]container. PortRangeProto {
442- "8080/tcp" : {"8080/tcp" },
443- "8080/udp" : {"8080/udp" },
444- "8080/ncp" : {"8080/ncp" },
445- "8080-8080/udp" : {"8080/udp" },
446- "8080-8082/tcp" : {"8080/tcp" , "8081/tcp" , "8082/tcp" },
443+ valids := map [string ][]network. Port {
444+ "8080/tcp" : {network . MustParsePort ( "8080/tcp" ) },
445+ "8080/udp" : {network . MustParsePort ( "8080/udp" ) },
446+ "8080/ncp" : {network . MustParsePort ( "8080/ncp" ) },
447+ "8080-8080/udp" : {network . MustParsePort ( "8080/udp" ) },
448+ "8080-8082/tcp" : {network . MustParsePort ( "8080/tcp" ), network . MustParsePort ( "8081/tcp" ), network . MustParsePort ( "8082/tcp" ) },
447449 }
448450 for expose , expectedError := range invalids {
449451 if _ , _ , _ , err := parseRun ([]string {fmt .Sprintf ("--expose=%v" , expose ), "img" , "cmd" }); err == nil || err .Error () != expectedError {
@@ -472,7 +474,7 @@ func TestParseWithExpose(t *testing.T) {
472474 if len (config .ExposedPorts ) != 2 {
473475 t .Fatalf ("Expected 2 exposed ports, got %v" , config .ExposedPorts )
474476 }
475- ports := []container. PortRangeProto { "80/tcp" , "81/tcp" }
477+ ports := []network. Port { network . MustParsePort ( "80/tcp" ), network . MustParsePort ( "81/tcp" ) }
476478 for _ , port := range ports {
477479 if _ , ok := config .ExposedPorts [port ]; ! ok {
478480 t .Fatalf ("Expected %v, got %v" , ports , config .ExposedPorts )
@@ -607,9 +609,9 @@ func TestParseNetworkConfig(t *testing.T) {
607609 expected : map [string ]* networktypes.EndpointSettings {
608610 "net1" : {
609611 IPAMConfig : & networktypes.EndpointIPAMConfig {
610- IPv4Address : "172.20.88.22" ,
611- IPv6Address : "2001:db8::8822" ,
612- LinkLocalIPs : []string { "169.254.2.2" , "fe80::169:254:2:2" },
612+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
613+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
614+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
613615 },
614616 Links : []string {"foo:bar" , "bar:baz" },
615617 Aliases : []string {"web1" , "web2" },
@@ -637,9 +639,9 @@ func TestParseNetworkConfig(t *testing.T) {
637639 "net1" : {
638640 DriverOpts : map [string ]string {"field1" : "value1" },
639641 IPAMConfig : & networktypes.EndpointIPAMConfig {
640- IPv4Address : "172.20.88.22" ,
641- IPv6Address : "2001:db8::8822" ,
642- LinkLocalIPs : []string { "169.254.2.2" , "fe80::169:254:2:2" },
642+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
643+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
644+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
643645 },
644646 Links : []string {"foo:bar" , "bar:baz" },
645647 Aliases : []string {"web1" , "web2" },
@@ -648,15 +650,15 @@ func TestParseNetworkConfig(t *testing.T) {
648650 "net3" : {
649651 DriverOpts : map [string ]string {"field3" : "value3" },
650652 IPAMConfig : & networktypes.EndpointIPAMConfig {
651- IPv4Address : "172.20.88.22" ,
652- IPv6Address : "2001:db8::8822" ,
653+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
654+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
653655 },
654656 Aliases : []string {"web3" },
655657 },
656658 "net4" : {
657659 MacAddress : "02:32:1c:23:00:04" ,
658660 IPAMConfig : & networktypes.EndpointIPAMConfig {
659- LinkLocalIPs : []string { "169.254.169.254" },
661+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.169.254" ) },
660662 },
661663 },
662664 },
@@ -672,8 +674,8 @@ func TestParseNetworkConfig(t *testing.T) {
672674 "field2" : "value2" ,
673675 },
674676 IPAMConfig : & networktypes.EndpointIPAMConfig {
675- IPv4Address : "172.20.88.22" ,
676- IPv6Address : "2001:db8::8822" ,
677+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
678+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
677679 },
678680 Aliases : []string {"web1" , "web2" },
679681 MacAddress : "02:32:1c:23:00:04" ,
0 commit comments