@@ -579,3 +579,75 @@ services:
579579 }
580580 c .Assert (expected )
581581}
582+
583+ func TestComposeUpWithIPv6 (t * testing.T ) {
584+ base := testutil .NewBaseWithIPv6Compatible (t )
585+
586+ subnet := "2001:aaa::/64"
587+ var dockerComposeYAML = fmt .Sprintf (`
588+ services:
589+ svc0:
590+ image: %s
591+ networks:
592+ - net0
593+ networks:
594+ net0:
595+ enable_ipv6: true
596+ ipam:
597+ config:
598+ - subnet: %s` , testutil .CommonImage , subnet )
599+
600+ comp := testutil .NewComposeDir (t , dockerComposeYAML )
601+ defer comp .CleanUp ()
602+ projectName := comp .ProjectName ()
603+ t .Logf ("projectName=%q" , projectName )
604+ base .ComposeCmd ("-f" , comp .YAMLFullPath (), "up" , "-d" ).AssertOK ()
605+ defer base .ComposeCmd ("-f" , comp .YAMLFullPath (), "down" , "-v" ).Run ()
606+
607+ inspectCmd := base .Cmd ("network" , "inspect" , projectName + "_net0" , "--format" , "\" {{range .IPAM.Config}}{{.Subnet}} {{end}}\" " )
608+ result := inspectCmd .Run ()
609+ stdoutContent := result .Stdout () + result .Stderr ()
610+ assert .Assert (inspectCmd .Base .T , result .ExitCode == 0 , stdoutContent )
611+
612+ if ! strings .Contains (stdoutContent , subnet ) {
613+ log .L .Errorf ("test failed, the actual subnets are %s" , stdoutContent )
614+ t .Fail ()
615+ return
616+ }
617+ }
618+
619+ func TestComposeUpWithIPv6Disabled (t * testing.T ) {
620+ base := testutil .NewBaseWithIPv6Compatible (t )
621+
622+ subnet := "2001:aab::/64"
623+ var dockerComposeYAML = fmt .Sprintf (`
624+ services:
625+ svc0:
626+ image: %s
627+ networks:
628+ - net0
629+ networks:
630+ net0:
631+ enable_ipv6: false
632+ ipam:
633+ config:
634+ - subnet: %s` , testutil .CommonImage , subnet )
635+
636+ comp := testutil .NewComposeDir (t , dockerComposeYAML )
637+ defer comp .CleanUp ()
638+ projectName := comp .ProjectName ()
639+ t .Logf ("projectName=%q" , projectName )
640+ base .ComposeCmd ("-f" , comp .YAMLFullPath (), "up" , "-d" ).AssertOK ()
641+ defer base .ComposeCmd ("-f" , comp .YAMLFullPath (), "down" , "-v" ).Run ()
642+
643+ inspectCmd := base .Cmd ("network" , "inspect" , projectName + "_net0" , "--format" , "\" {{range .IPAM.Config}}{{.Subnet}} {{end}}\" " )
644+ result := inspectCmd .Run ()
645+ stdoutContent := result .Stdout () + result .Stderr ()
646+ assert .Assert (inspectCmd .Base .T , result .ExitCode == 0 , stdoutContent )
647+
648+ if strings .Contains (stdoutContent , subnet ) {
649+ log .L .Errorf ("test failed, the actual subnets are %s" , stdoutContent )
650+ t .Fail ()
651+ return
652+ }
653+ }
0 commit comments