@@ -104,6 +104,61 @@ func TestCreateWithIPv6WithoutEnableIPv6Flag(t *testing.T) {
104104 t .Fatalf ("Network %s has no ULA prefix, expected one." , nwName )
105105}
106106
107+ // TestDefaultIPvOptOverride checks that when default-network-opts set enable_ipv4 or
108+ // enable_ipv6, and those values are overridden for a network, the default option
109+ // values don't show up in network inspect output. (Because it's confusing if the
110+ // default shows up when it's been overridden with a different value.)
111+ func TestDefaultIPvOptOverride (t * testing.T ) {
112+ ctx := setupTest (t )
113+ d := daemon .New (t )
114+ const opt4 = "false"
115+ const opt6 = "true"
116+ d .StartWithBusybox (ctx , t ,
117+ "--default-network-opt=bridge=com.docker.network.enable_ipv4=" + opt4 ,
118+ "--default-network-opt=bridge=com.docker.network.enable_ipv6=" + opt6 ,
119+ )
120+ defer d .Stop (t )
121+ c := d .NewClientT (t )
122+
123+ t .Run ("TestDefaultIPvOptOverride" , func (t * testing.T ) {
124+ for _ , override4 := range []bool {false , true } {
125+ for _ , override6 := range []bool {false , true } {
126+ t .Run (fmt .Sprintf ("override4=%v,override6=%v" , override4 , override6 ), func (t * testing.T ) {
127+ t .Parallel ()
128+ netName := fmt .Sprintf ("tdioo-%v-%v" , override4 , override6 )
129+ var nopts []func (* networktypes.CreateOptions )
130+ if override4 {
131+ nopts = append (nopts , network .WithIPv4 (true ))
132+ }
133+ if override6 {
134+ nopts = append (nopts , network .WithIPv6 ())
135+ }
136+ network .CreateNoError (ctx , t , c , netName , nopts ... )
137+ defer network .RemoveNoError (ctx , t , c , netName )
138+
139+ insp , err := c .NetworkInspect (ctx , netName , networktypes.InspectOptions {})
140+ assert .NilError (t , err )
141+ t .Log ("override4" , override4 , "override6" , override6 , "->" , insp .Options )
142+
143+ gotOpt4 , have4 := insp .Options [netlabel .EnableIPv4 ]
144+ assert .Check (t , is .Equal (have4 , ! override4 ))
145+ assert .Check (t , is .Equal (insp .EnableIPv4 , override4 ))
146+ if have4 {
147+ assert .Check (t , is .Equal (gotOpt4 , opt4 ))
148+ }
149+
150+ gotOpt6 , have6 := insp .Options [netlabel .EnableIPv6 ]
151+ assert .Check (t , is .Equal (have6 , ! override6 ))
152+ assert .Check (t , is .Equal (insp .EnableIPv6 , true ))
153+ if have6 {
154+ assert .Check (t , is .Equal (gotOpt6 , opt6 ))
155+ }
156+ })
157+ }
158+ }
159+ })
160+ }
161+
107162// Check that it's possible to create IPv6 networks with a 64-bit ip-range,
108163// in 64-bit and bigger subnets, with and without a gateway.
109164func Test64BitIPRange (t * testing.T ) {
0 commit comments