@@ -579,3 +579,73 @@ services:
579
579
}
580
580
c .Assert (expected )
581
581
}
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
+
606
+ inspectCmd := base .Cmd ("network" , "inspect" , projectName + "_net0" , "--format" , "\" {{range .IPAM.Config}}{{.Subnet}} {{end}}\" " )
607
+ result := inspectCmd .Run ()
608
+ stdoutContent := result .Stdout () + result .Stderr ()
609
+ assert .Assert (inspectCmd .Base .T , result .ExitCode == 0 , stdoutContent )
610
+
611
+ if ! strings .Contains (stdoutContent , subnet ) {
612
+ log .L .Errorf ("test failed, the actual subnets are %s" , stdoutContent )
613
+ t .Fail ()
614
+ return
615
+ }
616
+ }
617
+
618
+ func TestComposeUpWithIPv6Disabled (t * testing.T ) {
619
+ base := testutil .NewBaseWithIPv6Compatible (t )
620
+
621
+ subnet := "2001:aab::/64"
622
+ var dockerComposeYAML = fmt .Sprintf (`
623
+ services:
624
+ svc0:
625
+ image: %s
626
+ networks:
627
+ - net0
628
+ networks:
629
+ net0:
630
+ enable_ipv6: false
631
+ ipam:
632
+ config:
633
+ - subnet: %s` , testutil .CommonImage , subnet )
634
+
635
+ comp := testutil .NewComposeDir (t , dockerComposeYAML )
636
+ defer comp .CleanUp ()
637
+ projectName := comp .ProjectName ()
638
+ t .Logf ("projectName=%q" , projectName )
639
+ base .ComposeCmd ("-f" , comp .YAMLFullPath (), "up" , "-d" ).AssertOK ()
640
+
641
+ inspectCmd := base .Cmd ("network" , "inspect" , projectName + "_net0" , "--format" , "\" {{range .IPAM.Config}}{{.Subnet}} {{end}}\" " )
642
+ result := inspectCmd .Run ()
643
+ stdoutContent := result .Stdout () + result .Stderr ()
644
+ assert .Assert (inspectCmd .Base .T , result .ExitCode == 0 , stdoutContent )
645
+
646
+ if strings .Contains (stdoutContent , subnet ) {
647
+ log .L .Errorf ("test failed, the actual subnets are %s" , stdoutContent )
648
+ t .Fail ()
649
+ return
650
+ }
651
+ }
0 commit comments