@@ -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 )
@@ -447,12 +448,12 @@ func TestParseWithExpose(t *testing.T) {
447448 }
448449 })
449450 t .Run ("valid" , func (t * testing.T ) {
450- tests := map [string ][]container. PortRangeProto {
451- "8080/tcp" : {"8080/tcp" },
452- "8080/udp" : {"8080/udp" },
453- "8080/ncp" : {"8080/ncp" },
454- "8080-8080/udp" : {"8080/udp" },
455- "8080-8082/tcp" : {"8080/tcp" , "8081/tcp" , "8082/tcp" },
451+ tests := map [string ][]network. Port {
452+ "8080/tcp" : {network . MustParsePort ( "8080/tcp" ) },
453+ "8080/udp" : {network . MustParsePort ( "8080/udp" ) },
454+ "8080/ncp" : {network . MustParsePort ( "8080/ncp" ) },
455+ "8080-8080/udp" : {network . MustParsePort ( "8080/udp" ) },
456+ "8080-8082/tcp" : {network . MustParsePort ( "8080/tcp" ), network . MustParsePort ( "8081/tcp" ), network . MustParsePort ( "8082/tcp" ) },
456457 }
457458 for expose , exposedPorts := range tests {
458459 t .Run (expose , func (t * testing.T ) {
@@ -471,7 +472,7 @@ func TestParseWithExpose(t *testing.T) {
471472 config , _ , _ , err := parseRun ([]string {"--publish=80" , "--expose=80-81/tcp" , "img" , "cmd" })
472473 assert .NilError (t , err )
473474 assert .Check (t , is .Len (config .ExposedPorts , 2 ))
474- ports := []container. PortRangeProto { "80/tcp" , "81/tcp" }
475+ ports := []network. Port { network . MustParsePort ( "80/tcp" ), network . MustParsePort ( "81/tcp" ) }
475476 for _ , port := range ports {
476477 _ , ok := config .ExposedPorts [port ]
477478 assert .Check (t , ok , "missing port %q in exposed ports" , port )
@@ -573,21 +574,21 @@ func TestParseNetworkConfig(t *testing.T) {
573574 tests := []struct {
574575 name string
575576 flags []string
576- expected map [string ]* networktypes .EndpointSettings
577+ expected map [string ]* network .EndpointSettings
577578 expectedCfg container.Config
578579 expectedHostCfg container.HostConfig
579580 expectedErr string
580581 }{
581582 {
582583 name : "single-network-legacy" ,
583584 flags : []string {"--network" , "net1" },
584- expected : map [string ]* networktypes .EndpointSettings {},
585+ expected : map [string ]* network .EndpointSettings {},
585586 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
586587 },
587588 {
588589 name : "single-network-advanced" ,
589590 flags : []string {"--network" , "name=net1" },
590- expected : map [string ]* networktypes .EndpointSettings {},
591+ expected : map [string ]* network .EndpointSettings {},
591592 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
592593 },
593594 {
@@ -603,12 +604,12 @@ func TestParseNetworkConfig(t *testing.T) {
603604 "--network-alias" , "web1" ,
604605 "--network-alias" , "web2" ,
605606 },
606- expected : map [string ]* networktypes .EndpointSettings {
607+ expected : map [string ]* network .EndpointSettings {
607608 "net1" : {
608- IPAMConfig : & networktypes .EndpointIPAMConfig {
609- IPv4Address : "172.20.88.22" ,
610- IPv6Address : "2001:db8::8822" ,
611- LinkLocalIPs : []string { "169.254.2.2" , "fe80::169:254:2:2" },
609+ IPAMConfig : & network .EndpointIPAMConfig {
610+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
611+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
612+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
612613 },
613614 Links : []string {"foo:bar" , "bar:baz" },
614615 Aliases : []string {"web1" , "web2" },
@@ -632,30 +633,30 @@ func TestParseNetworkConfig(t *testing.T) {
632633 "--network" , "name=net3,alias=web3,driver-opt=field3=value3,ip=172.20.88.22,ip6=2001:db8::8822" ,
633634 "--network" , "name=net4,mac-address=02:32:1c:23:00:04,link-local-ip=169.254.169.254" ,
634635 },
635- expected : map [string ]* networktypes .EndpointSettings {
636+ expected : map [string ]* network .EndpointSettings {
636637 "net1" : {
637638 DriverOpts : map [string ]string {"field1" : "value1" },
638- IPAMConfig : & networktypes .EndpointIPAMConfig {
639- IPv4Address : "172.20.88.22" ,
640- IPv6Address : "2001:db8::8822" ,
641- LinkLocalIPs : []string { "169.254.2.2" , "fe80::169:254:2:2" },
639+ IPAMConfig : & network .EndpointIPAMConfig {
640+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
641+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
642+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.2.2" ), netip . MustParseAddr ( "fe80::169:254:2:2" ) },
642643 },
643644 Links : []string {"foo:bar" , "bar:baz" },
644645 Aliases : []string {"web1" , "web2" },
645646 },
646647 "net2" : {},
647648 "net3" : {
648649 DriverOpts : map [string ]string {"field3" : "value3" },
649- IPAMConfig : & networktypes .EndpointIPAMConfig {
650- IPv4Address : "172.20.88.22" ,
651- IPv6Address : "2001:db8::8822" ,
650+ IPAMConfig : & network .EndpointIPAMConfig {
651+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
652+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
652653 },
653654 Aliases : []string {"web3" },
654655 },
655656 "net4" : {
656657 MacAddress : "02:32:1c:23:00:04" ,
657- IPAMConfig : & networktypes .EndpointIPAMConfig {
658- LinkLocalIPs : []string { "169.254.169.254" },
658+ IPAMConfig : & network .EndpointIPAMConfig {
659+ LinkLocalIPs : []netip. Addr { netip . MustParseAddr ( "169.254.169.254" ) },
659660 },
660661 },
661662 },
@@ -664,15 +665,15 @@ func TestParseNetworkConfig(t *testing.T) {
664665 {
665666 name : "single-network-advanced-with-options" ,
666667 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" },
667- expected : map [string ]* networktypes .EndpointSettings {
668+ expected : map [string ]* network .EndpointSettings {
668669 "net1" : {
669670 DriverOpts : map [string ]string {
670671 "field1" : "value1" ,
671672 "field2" : "value2" ,
672673 },
673- IPAMConfig : & networktypes .EndpointIPAMConfig {
674- IPv4Address : "172.20.88.22" ,
675- IPv6Address : "2001:db8::8822" ,
674+ IPAMConfig : & network .EndpointIPAMConfig {
675+ IPv4Address : netip . MustParseAddr ( "172.20.88.22" ) ,
676+ IPv6Address : netip . MustParseAddr ( "2001:db8::8822" ) ,
676677 },
677678 Aliases : []string {"web1" , "web2" },
678679 MacAddress : "02:32:1c:23:00:04" ,
@@ -684,13 +685,13 @@ func TestParseNetworkConfig(t *testing.T) {
684685 {
685686 name : "multiple-networks" ,
686687 flags : []string {"--network" , "net1" , "--network" , "name=net2" },
687- expected : map [string ]* networktypes .EndpointSettings {"net1" : {}, "net2" : {}},
688+ expected : map [string ]* network .EndpointSettings {"net1" : {}, "net2" : {}},
688689 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
689690 },
690691 {
691692 name : "advanced-options-with-standalone-mac-address-flag" ,
692693 flags : []string {"--network=name=net1,alias=foobar" , "--mac-address" , "52:0f:f3:dc:50:10" },
693- expected : map [string ]* networktypes .EndpointSettings {
694+ expected : map [string ]* network .EndpointSettings {
694695 "net1" : {
695696 Aliases : []string {"foobar" },
696697 MacAddress : "52:0f:f3:dc:50:10" ,
0 commit comments