@@ -229,3 +229,60 @@ func TestContainerInspectState(t *testing.T) {
229
229
}
230
230
231
231
}
232
+
233
+ func TestContainerInspectHostConfig (t * testing.T ) {
234
+ testContainer := testutil .Identifier (t )
235
+
236
+ base := testutil .NewBase (t )
237
+ defer base .Cmd ("rm" , "-f" , testContainer ).Run ()
238
+
239
+ // Run a container with various HostConfig options
240
+ base .Cmd ("run" , "-d" , "--name" , testContainer ,
241
+ "--cpuset-cpus" , "0-1" ,
242
+ "--cpuset-mems" , "0" ,
243
+ "--blkio-weight" , "500" ,
244
+ "--cpu-shares" , "1024" ,
245
+ "--cpu-quota" , "100000" ,
246
+ "--group-add" , "1000" ,
247
+ "--group-add" , "2000" ,
248
+ "--add-host" , "host1:10.0.0.1" ,
249
+ "--add-host" , "host2:10.0.0.2" ,
250
+ "--ipc" , "host" ,
251
+ testutil .AlpineImage , "sleep" , "infinity" ).AssertOK ()
252
+
253
+ inspect := base .InspectContainer (testContainer )
254
+
255
+ assert .Equal (t , "0-1" , inspect .HostConfig .CPUSetCPUs )
256
+ assert .Equal (t , "0" , inspect .HostConfig .CPUSetMems )
257
+ assert .Equal (t , uint16 (500 ), inspect .HostConfig .BlkioWeight )
258
+ assert .Equal (t , uint64 (1024 ), inspect .HostConfig .CPUShares )
259
+ assert .Equal (t , int64 (100000 ), inspect .HostConfig .CPUQuota )
260
+ assert .DeepEqual (t , []string {"1000" , "2000" }, inspect .HostConfig .GroupAdd )
261
+ expectedExtraHosts := []string {"host1:10.0.0.1" , "host2:10.0.0.2" }
262
+ assert .DeepEqual (t , expectedExtraHosts , inspect .HostConfig .ExtraHosts )
263
+ assert .Equal (t , "host" , inspect .HostConfig .IpcMode )
264
+ assert .Equal (t , "json-file" , inspect .HostConfig .LogConfig .Type )
265
+ assert .Equal (t , "json-file" , inspect .HostConfig .LogConfig .Config .Driver )
266
+ }
267
+
268
+ func TestContainerInspectHostConfigDefaults (t * testing.T ) {
269
+ testContainer := testutil .Identifier (t )
270
+
271
+ base := testutil .NewBase (t )
272
+ defer base .Cmd ("rm" , "-f" , testContainer ).Run ()
273
+
274
+ // Run a container without specifying HostConfig options
275
+ base .Cmd ("run" , "-d" , "--name" , testContainer , testutil .AlpineImage , "sleep" , "infinity" ).AssertOK ()
276
+
277
+ inspect := base .InspectContainer (testContainer )
278
+ assert .Equal (t , "" , inspect .HostConfig .CPUSetCPUs )
279
+ assert .Equal (t , "" , inspect .HostConfig .CPUSetMems )
280
+ assert .Equal (t , uint16 (0 ), inspect .HostConfig .BlkioWeight )
281
+ assert .Equal (t , uint64 (0 ), inspect .HostConfig .CPUShares )
282
+ assert .Equal (t , int64 (0 ), inspect .HostConfig .CPUQuota )
283
+ assert .Equal (t , 0 , len (inspect .HostConfig .GroupAdd ))
284
+ assert .Equal (t , 0 , len (inspect .HostConfig .ExtraHosts ))
285
+ assert .Equal (t , "" , inspect .HostConfig .IpcMode )
286
+ assert .Equal (t , "json-file" , inspect .HostConfig .LogConfig .Type )
287
+ assert .Equal (t , "json-file" , inspect .HostConfig .LogConfig .Config .Driver )
288
+ }
0 commit comments