@@ -510,6 +510,7 @@ func TestParseNetworkConfig(t *testing.T) {
510510 name string
511511 flags []string
512512 expected map [string ]* networktypes.EndpointSettings
513+ expectedCfg container.Config
513514 expectedHostCfg container.HostConfig
514515 expectedErr string
515516 }{
@@ -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 },
590598 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,9 +610,11 @@ 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 },
617+ expectedCfg : container.Config {MacAddress : "02:32:1c:23:00:04" },
608618 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
609619 },
610620 {
@@ -613,6 +623,18 @@ func TestParseNetworkConfig(t *testing.T) {
613623 expected : map [string ]* networktypes.EndpointSettings {"net1" : {}, "net2" : {}},
614624 expectedHostCfg : container.HostConfig {NetworkMode : "net1" },
615625 },
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" },
637+ },
616638 {
617639 name : "conflict-network" ,
618640 flags : []string {"--network" , "duplicate" , "--network" , "name=duplicate" },
@@ -638,18 +660,34 @@ 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 )
690+ assert .DeepEqual (t , config .MacAddress , tc .expectedCfg .MacAddress )
653691 assert .DeepEqual (t , hConfig .NetworkMode , tc .expectedHostCfg .NetworkMode )
654692 assert .DeepEqual (t , nwConfig .EndpointsConfig , tc .expected )
655693 })
0 commit comments