@@ -507,23 +507,24 @@ func TestParseDevice(t *testing.T) {
507507
508508func TestParseNetworkConfig (t * testing.T ) {
509509 tests := []struct {
510- name string
511- flags []string
512- expected map [string ]* networktypes.EndpointSettings
513- expectedCfg container.HostConfig
514- expectedErr string
510+ name string
511+ flags []string
512+ expected map [string ]* networktypes.EndpointSettings
513+ expectedCfg container.Config
514+ expectedHostCfg container.HostConfig
515+ expectedErr string
515516 }{
516517 {
517- name : "single-network-legacy" ,
518- flags : []string {"--network" , "net1" },
519- expected : map [string ]* networktypes.EndpointSettings {},
520- expectedCfg : container.HostConfig {NetworkMode : "net1" },
518+ name : "single-network-legacy" ,
519+ flags : []string {"--network" , "net1" },
520+ expected : map [string ]* networktypes.EndpointSettings {},
521+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
521522 },
522523 {
523- name : "single-network-advanced" ,
524- flags : []string {"--network" , "name=net1" },
525- expected : map [string ]* networktypes.EndpointSettings {},
526- expectedCfg : container.HostConfig {NetworkMode : "net1" },
524+ name : "single-network-advanced" ,
525+ flags : []string {"--network" , "name=net1" },
526+ expected : map [string ]* networktypes.EndpointSettings {},
527+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
527528 },
528529 {
529530 name : "single-network-legacy-with-options" ,
@@ -549,7 +550,7 @@ func TestParseNetworkConfig(t *testing.T) {
549550 Aliases : []string {"web1" , "web2" },
550551 },
551552 },
552- expectedCfg : container.HostConfig {NetworkMode : "net1" },
553+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
553554 },
554555 {
555556 name : "multiple-network-advanced-mixed" ,
@@ -565,6 +566,7 @@ func TestParseNetworkConfig(t *testing.T) {
565566 "--network-alias" , "web2" ,
566567 "--network" , "net2" ,
567568 "--network" , "name=net3,alias=web3,driver-opt=field3=value3,ip=172.20.88.22,ip6=2001:db8::8822" ,
569+ "--network" , "name=net4,mac-address=02:32:1c:23:00:04,link-local-ip=169.254.169.254" ,
568570 },
569571 expected : map [string ]* networktypes.EndpointSettings {
570572 "net1" : {
@@ -586,12 +588,18 @@ func TestParseNetworkConfig(t *testing.T) {
586588 },
587589 Aliases : []string {"web3" },
588590 },
591+ "net4" : {
592+ MacAddress : "02:32:1c:23:00:04" ,
593+ IPAMConfig : & networktypes.EndpointIPAMConfig {
594+ LinkLocalIPs : []string {"169.254.169.254" },
595+ },
596+ },
589597 },
590- expectedCfg : container.HostConfig {NetworkMode : "net1" },
598+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
591599 },
592600 {
593601 name : "single-network-advanced-with-options" ,
594- 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" },
602+ 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 " },
595603 expected : map [string ]* networktypes.EndpointSettings {
596604 "net1" : {
597605 DriverOpts : map [string ]string {
@@ -602,16 +610,30 @@ func TestParseNetworkConfig(t *testing.T) {
602610 IPv4Address : "172.20.88.22" ,
603611 IPv6Address : "2001:db8::8822" ,
604612 },
605- Aliases : []string {"web1" , "web2" },
613+ Aliases : []string {"web1" , "web2" },
614+ MacAddress : "02:32:1c:23:00:04" ,
606615 },
607616 },
608- expectedCfg : container.HostConfig {NetworkMode : "net1" },
617+ expectedCfg : container.Config {MacAddress : "02:32:1c:23:00:04" },
618+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
609619 },
610620 {
611- name : "multiple-networks" ,
612- flags : []string {"--network" , "net1" , "--network" , "name=net2" },
613- expected : map [string ]* networktypes.EndpointSettings {"net1" : {}, "net2" : {}},
614- expectedCfg : container.HostConfig {NetworkMode : "net1" },
621+ name : "multiple-networks" ,
622+ flags : []string {"--network" , "net1" , "--network" , "name=net2" },
623+ expected : map [string ]* networktypes.EndpointSettings {"net1" : {}, "net2" : {}},
624+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
625+ },
626+ {
627+ name : "advanced-options-with-standalone-mac-address-flag" ,
628+ flags : []string {"--network=name=net1,alias=foobar" , "--mac-address" , "52:0f:f3:dc:50:10" },
629+ expected : map [string ]* networktypes.EndpointSettings {
630+ "net1" : {
631+ Aliases : []string {"foobar" },
632+ MacAddress : "52:0f:f3:dc:50:10" ,
633+ },
634+ },
635+ expectedCfg : container.Config {MacAddress : "52:0f:f3:dc:50:10" },
636+ expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
615637 },
616638 {
617639 name : "conflict-network" ,
@@ -638,19 +660,35 @@ func TestParseNetworkConfig(t *testing.T) {
638660 flags : []string {"--network" , "name=host" , "--network" , "net1" },
639661 expectedErr : `conflicting options: cannot attach both user-defined and non-user-defined network-modes` ,
640662 },
663+ {
664+ name : "conflict-options-link-local-ip" ,
665+ flags : []string {"--network" , "name=net1,link-local-ip=169.254.169.254" , "--link-local-ip" , "169.254.10.8" },
666+ expectedErr : `conflicting options: cannot specify both --link-local-ip and per-network link-local IP addresses` ,
667+ },
668+ {
669+ name : "conflict-options-mac-address" ,
670+ flags : []string {"--network" , "name=net1,mac-address=02:32:1c:23:00:04" , "--mac-address" , "02:32:1c:23:00:04" },
671+ expectedErr : `conflicting options: cannot specify both --mac-address and per-network MAC address` ,
672+ },
673+ {
674+ name : "invalid-mac-address" ,
675+ flags : []string {"--network" , "name=net1,mac-address=foobar" },
676+ expectedErr : "foobar is not a valid mac address" ,
677+ },
641678 }
642679
643680 for _ , tc := range tests {
644681 t .Run (tc .name , func (t * testing.T ) {
645- _ , hConfig , nwConfig , err := parseRun (tc .flags )
682+ config , hConfig , nwConfig , err := parseRun (tc .flags )
646683
647684 if tc .expectedErr != "" {
648685 assert .Error (t , err , tc .expectedErr )
649686 return
650687 }
651688
652689 assert .NilError (t , err )
653- assert .DeepEqual (t , hConfig .NetworkMode , tc .expectedCfg .NetworkMode )
690+ assert .DeepEqual (t , config .MacAddress , tc .expectedCfg .MacAddress )
691+ assert .DeepEqual (t , hConfig .NetworkMode , tc .expectedHostCfg .NetworkMode )
654692 assert .DeepEqual (t , nwConfig .EndpointsConfig , tc .expected )
655693 })
656694 }
0 commit comments