@@ -4,14 +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"
14- networktypes "github.com/moby/moby/api/types/network"
15+ "github.com/moby/moby/api/types/network"
1516 "github.com/spf13/pflag"
1617 "gotest.tools/v3/assert"
1718 is "gotest.tools/v3/assert/cmp"
@@ -42,7 +43,7 @@ func TestValidateAttach(t *testing.T) {
4243 }
4344}
4445
45- func parseRun (args []string ) (* container.Config , * container.HostConfig , * networktypes .NetworkingConfig , error ) {
46+ func parseRun (args []string ) (* container.Config , * container.HostConfig , * network .NetworkingConfig , error ) {
4647 flags , copts := setupRunFlags ()
4748 if err := flags .Parse (args ); err != nil {
4849 return nil , nil , nil , err
@@ -63,7 +64,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
6364 return flags , copts
6465}
6566
66- func mustParse (t * testing.T , args string ) (* container.Config , * container.HostConfig , * networktypes .NetworkingConfig ) {
67+ func mustParse (t * testing.T , args string ) (* container.Config , * container.HostConfig , * network .NetworkingConfig ) {
6768 t .Helper ()
6869 config , hostConfig , nwConfig , err := parseRun (append (strings .Split (args , " " ), "ubuntu" , "bash" ))
6970 assert .NilError (t , err )
@@ -438,12 +439,12 @@ func TestParseWithExpose(t *testing.T) {
438439 "8080-NaN/tcp" : `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax` ,
439440 "1234567890-8080/tcp" : `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range` ,
440441 }
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" },
442+ valids := map [string ][]network. Port {
443+ "8080/tcp" : {network . MustParsePort ( "8080/tcp" ) },
444+ "8080/udp" : {network . MustParsePort ( "8080/udp" ) },
445+ "8080/ncp" : {network . MustParsePort ( "8080/ncp" ) },
446+ "8080-8080/udp" : {network . MustParsePort ( "8080/udp" ) },
447+ "8080-8082/tcp" : {network . MustParsePort ( "8080/tcp" ), network . MustParsePort ( "8081/tcp" ), network . MustParsePort ( "8082/tcp" ) },
447448 }
448449 for expose , expectedError := range invalids {
449450 if _ , _ , _ , err := parseRun ([]string {fmt .Sprintf ("--expose=%v" , expose ), "img" , "cmd" }); err == nil || err .Error () != expectedError {
@@ -472,7 +473,7 @@ func TestParseWithExpose(t *testing.T) {
472473 if len (config .ExposedPorts ) != 2 {
473474 t .Fatalf ("Expected 2 exposed ports, got %v" , config .ExposedPorts )
474475 }
475- ports := []container. PortRangeProto { "80/tcp" , "81/tcp" }
476+ ports := []network. Port { network . MustParsePort ( "80/tcp" ), network . MustParsePort ( "81/tcp" ) }
476477 for _ , port := range ports {
477478 if _ , ok := config .ExposedPorts [port ]; ! ok {
478479 t .Fatalf ("Expected %v, got %v" , ports , config .ExposedPorts )
@@ -574,21 +575,21 @@ func TestParseNetworkConfig(t *testing.T) {
574575 tests := []struct {
575576 name string
576577 flags []string
577- expected map [string ]* networktypes .EndpointSettings
578+ expected map [string ]* network .EndpointSettings
578579 expectedCfg container.Config
579580 expectedHostCfg container.HostConfig
580581 expectedErr string
581582 }{
582583 {
583584 name : "single-network-legacy" ,
584585 flags : []string {"--network" , "net1" },
585- expected : map [string ]* networktypes .EndpointSettings {},
586+ expected : map [string ]* network .EndpointSettings {},
586587 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
587588 },
588589 {
589590 name : "single-network-advanced" ,
590591 flags : []string {"--network" , "name=net1" },
591- expected : map [string ]* networktypes .EndpointSettings {},
592+ expected : map [string ]* network .EndpointSettings {},
592593 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
593594 },
594595 {
@@ -604,12 +605,12 @@ func TestParseNetworkConfig(t *testing.T) {
604605 "--network-alias" , "web1" ,
605606 "--network-alias" , "web2" ,
606607 },
607- expected : map [string ]* networktypes .EndpointSettings {
608+ expected : map [string ]* network .EndpointSettings {
608609 "net1" : {
609- 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" },
610+ IPAMConfig : & network .EndpointIPAMConfig {
611+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
612+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
613+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
613614 },
614615 Links : []string {"foo:bar" , "bar:baz" },
615616 Aliases : []string {"web1" , "web2" },
@@ -633,30 +634,30 @@ func TestParseNetworkConfig(t *testing.T) {
633634 "--network" , "name=net3,alias=web3,driver-opt=field3=value3,ip=172.20.88.22,ip6=2001:db8::8822" ,
634635 "--network" , "name=net4,mac-address=02:32:1c:23:00:04,link-local-ip=169.254.169.254" ,
635636 },
636- expected : map [string ]* networktypes .EndpointSettings {
637+ expected : map [string ]* network .EndpointSettings {
637638 "net1" : {
638639 DriverOpts : map [string ]string {"field1" : "value1" },
639- 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" },
640+ IPAMConfig : & network .EndpointIPAMConfig {
641+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
642+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
643+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
643644 },
644645 Links : []string {"foo:bar" , "bar:baz" },
645646 Aliases : []string {"web1" , "web2" },
646647 },
647648 "net2" : {},
648649 "net3" : {
649650 DriverOpts : map [string ]string {"field3" : "value3" },
650- IPAMConfig : & networktypes .EndpointIPAMConfig {
651- IPv4Address : "172.20.88.22" ,
652- IPv6Address : "2001:db8::8822" ,
651+ IPAMConfig : & network .EndpointIPAMConfig {
652+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
653+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
653654 },
654655 Aliases : []string {"web3" },
655656 },
656657 "net4" : {
657658 MacAddress : "02:32:1c:23:00:04" ,
658- IPAMConfig : & networktypes .EndpointIPAMConfig {
659- LinkLocalIPs : []string { "169.254.169.254" },
659+ IPAMConfig : & network .EndpointIPAMConfig {
660+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.169.254" ) },
660661 },
661662 },
662663 },
@@ -665,15 +666,15 @@ func TestParseNetworkConfig(t *testing.T) {
665666 {
666667 name : "single-network-advanced-with-options" ,
667668 flags : []string {"--network" , "name=net1,alias=web1,alias=web2,driver-opt=field1=value1,driver-opt=field2=value2,ip=172.20.88.22,ip6=2001:db8::8822,mac-address=02:32:1c:23:00:04" },
668- expected : map [string ]* networktypes .EndpointSettings {
669+ expected : map [string ]* network .EndpointSettings {
669670 "net1" : {
670671 DriverOpts : map [string ]string {
671672 "field1" : "value1" ,
672673 "field2" : "value2" ,
673674 },
674- IPAMConfig : & networktypes .EndpointIPAMConfig {
675- IPv4Address : "172.20.88.22" ,
676- IPv6Address : "2001:db8::8822" ,
675+ IPAMConfig : & network .EndpointIPAMConfig {
676+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
677+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
677678 },
678679 Aliases : []string {"web1" , "web2" },
679680 MacAddress : "02:32:1c:23:00:04" ,
@@ -685,13 +686,13 @@ func TestParseNetworkConfig(t *testing.T) {
685686 {
686687 name : "multiple-networks" ,
687688 flags : []string {"--network" , "net1" , "--network" , "name=net2" },
688- expected : map [string ]* networktypes .EndpointSettings {"net1" : {}, "net2" : {}},
689+ expected : map [string ]* network .EndpointSettings {"net1" : {}, "net2" : {}},
689690 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
690691 },
691692 {
692693 name : "advanced-options-with-standalone-mac-address-flag" ,
693694 flags : []string {"--network=name=net1,alias=foobar" , "--mac-address" , "52:0f:f3:dc:50:10" },
694- expected : map [string ]* networktypes .EndpointSettings {
695+ expected : map [string ]* network .EndpointSettings {
695696 "net1" : {
696697 Aliases : []string {"foobar" },
697698 MacAddress : "52:0f:f3:dc:50:10" ,
0 commit comments