Skip to content

Commit eb75366

Browse files
committed
test devices
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 6304ad1 commit eb75366

File tree

1 file changed

+23
-79
lines changed

1 file changed

+23
-79
lines changed

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 23 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,11 @@ func TestContainerInspectHostConfig(t *testing.T) {
251251
"--read-only",
252252
"--shm-size", "256m",
253253
"--uts", "host",
254-
"--device", "/dev/null:/dev/null",
255254
"--sysctl", "net.core.somaxconn=1024",
256255
"--runtime", "io.containerd.runc.v2",
257256
testutil.AlpineImage, "sleep", "infinity").AssertOK()
258257

259258
inspect := base.InspectContainer(testContainer)
260-
t.Log("==========")
261-
t.Log(inspect.HostConfig)
262-
t.Log("==========")
263-
// "--runtime", "io.containerd.runtime.v1.linux",
264259

265260
assert.Equal(t, "0-1", inspect.HostConfig.CPUSetCPUs)
266261
assert.Equal(t, "0", inspect.HostConfig.CPUSetMems)
@@ -277,11 +272,6 @@ func TestContainerInspectHostConfig(t *testing.T) {
277272
assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
278273
assert.Equal(t, "host", inspect.HostConfig.UTSMode)
279274
assert.Equal(t, int64(268435456), inspect.HostConfig.ShmSize)
280-
// assert.Equal(t, "io.containerd.runtime.v1.linux", inspect.HostConfig.Runtime)
281-
// expectedSysctls := map[string]string{
282-
// "net.core.somaxconn": "1024",
283-
// }
284-
// assert.Equal(t, bool(true), inspect.HostConfig.OomKillDisable)
285275
}
286276

287277
func TestContainerInspectHostConfigDefaults(t *testing.T) {
@@ -305,19 +295,14 @@ func TestContainerInspectHostConfigDefaults(t *testing.T) {
305295
assert.Equal(t, "private", inspect.HostConfig.IpcMode)
306296
assert.Equal(t, "", inspect.HostConfig.LogConfig.Driver)
307297
assert.Equal(t, int64(0), inspect.HostConfig.Memory)
308-
t.Logf("inspect.HostConfig.Memory in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.Memory)
309298
assert.Equal(t, int64(0), inspect.HostConfig.MemorySwap)
310-
t.Logf("inspect.HostConfig.MemorySwap in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.MemorySwap)
311299
assert.Equal(t, bool(false), inspect.HostConfig.OomKillDisable)
312-
t.Logf("inspect.HostConfig.OomKillDisable in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.OomKillDisable)
313300
assert.Equal(t, bool(false), inspect.HostConfig.ReadonlyRootfs)
314301
assert.Equal(t, "", inspect.HostConfig.UTSMode)
315302
assert.Equal(t, int64(67108864), inspect.HostConfig.ShmSize)
316303
assert.Equal(t, "runc", inspect.HostConfig.Runtime)
317304
assert.Equal(t, 0, len(inspect.HostConfig.Sysctls))
318305
assert.Equal(t, 0, len(inspect.HostConfig.Devices))
319-
// t.Logf("len(inspect.HostConfig.Sysctls) in TestContainerInspectHostConfigDefaults: %+v", len(inspect.HostConfig.Sysctls))
320-
// t.Logf("len(inspect.HostConfig.Devices) in TestContainerInspectHostConfigDefaults: %+v", len(inspect.HostConfig.Devices))
321306
}
322307

323308
func TestContainerInspectHostConfigDNS(t *testing.T) {
@@ -378,16 +363,15 @@ func TestContainerInspectHostConfigPID(t *testing.T) {
378363
// Run the first container
379364
base.Cmd("run", "-d", "--name", testContainer1, testutil.AlpineImage, "sleep", "infinity").AssertOK()
380365

381-
container1ID := strings.TrimSpace(base.Cmd("inspect", "-f", "{{.Id}}", testContainer1).Out())
366+
container1_ID := strings.TrimSpace(base.Cmd("inspect", "-f", "{{.Id}}", testContainer1).Out())
382367

383-
// Run a container with PID namespace options
384368
base.Cmd("run", "-d", "--name", testContainer2,
385369
"--pid", fmt.Sprintf("container:%s", testContainer1),
386370
testutil.AlpineImage, "sleep", "infinity").AssertOK()
387371

388372
inspect := base.InspectContainer(testContainer2)
389373

390-
assert.Equal(t, fmt.Sprintf("container:%s", container1ID), inspect.HostConfig.PidMode)
374+
assert.Equal(t, fmt.Sprintf("container:%s", container1_ID), inspect.HostConfig.PidMode)
391375

392376
}
393377

@@ -397,71 +381,31 @@ func TestContainerInspectHostConfigPIDDefaults(t *testing.T) {
397381
base := testutil.NewBase(t)
398382
defer base.Cmd("rm", "-f", testContainer).Run()
399383

400-
// Run a container without specifying PID options
401384
base.Cmd("run", "-d", "--name", testContainer, testutil.AlpineImage, "sleep", "infinity").AssertOK()
402385

403386
inspect := base.InspectContainer(testContainer)
404387

405-
// Check that PID mode is empty (private) by default
406388
assert.Equal(t, "", inspect.HostConfig.PidMode)
407389
}
408390

409-
// assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
410-
// assert.Equal(t, "host", inspect.HostConfig.UTSMode)
411-
// assert.Equal(t, int64(268435456), inspect.HostConfig.ShmSize)
412-
// assert.Equal(t, "io.containerd.runtime.v1.linux", inspect.HostConfig.Runtime)
413-
// expectedSysctls := map[string]string{
414-
// "net.core.somaxconn": "1024",
415-
// }
416-
// assert.DeepEqual(t, expectedSysctls, inspect.HostConfig.Sysctls)
417-
// expectedDevices := []string{"/dev/null:/dev/null"}
418-
// assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
419-
420-
// func TestContainerInspectHostConfigAdvanced(t *testing.T) {
421-
// testContainer := testutil.Identifier(t)
422-
423-
// base := testutil.NewBase(t)
424-
// defer base.Cmd("rm", "-f", testContainer).Run()
425-
426-
// // Run a container with various advanced HostConfig options
427-
// base.Cmd("run", "-d", "--name", testContainer,
428-
// "--read-only",
429-
// "--uts", "host",
430-
// "--shm-size", "256m",
431-
// "--runtime", "io.containerd.runtime.v1.linux",
432-
// "--sysctl", "net.core.somaxconn=1024",
433-
// "--device", "/dev/null:/dev/null",
434-
// testutil.AlpineImage, "sleep", "infinity").AssertOK()
435-
436-
// inspect := base.InspectContainer(testContainer)
437-
438-
// // Check ReadonlyRootfs
439-
// assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
440-
441-
// // Check UTSMode
442-
// assert.Equal(t, "host", inspect.HostConfig.UTSMode)
443-
444-
// // Check ShmSize
445-
// assert.Equal(t, int64(268435456), inspect.HostConfig.ShmSize)
446-
447-
// // Check Runtime
448-
// assert.Equal(t, "io.containerd.runtime.v1.linux", inspect.HostConfig.Runtime)
449-
450-
// // Check Sysctls
451-
// expectedSysctls := map[string]string{
452-
// "net.core.somaxconn": "1024",
453-
// }
454-
// assert.DeepEqual(t, expectedSysctls, inspect.HostConfig.Sysctls)
455-
456-
// // Check Devices
457-
// expectedDevices := []string{"/dev/null:/dev/null"}
458-
// assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
459-
460-
// // Log the entire HostConfig for debugging
461-
// hostConfigJSON, err := json.MarshalIndent(inspect.HostConfig, "", " ")
462-
// if err != nil {
463-
// t.Errorf("Failed to marshal HostConfig: %v", err)
464-
// } else {
465-
// t.Logf("HostConfig in TestContainerInspectHostConfigAdvanced:\n%s", string(hostConfigJSON))
466-
// }
467-
// }
391+
func TestContainerInspectDevices(t *testing.T) {
392+
testContainer := testutil.Identifier(t)
393+
394+
base := testutil.NewBase(t)
395+
defer base.Cmd("rm", "-f", testContainer).Run()
396+
397+
base.Cmd("run", "-d", "--name", testContainer,
398+
"--device", "/dev/null:/dev/null",
399+
testutil.AlpineImage, "sleep", "infinity").AssertOK()
400+
401+
inspect := base.InspectContainer(testContainer)
402+
403+
expectedDevices := []dockercompat.DeviceMapping{
404+
{
405+
PathOnHost: "/dev/null",
406+
PathInContainer: "/dev/null",
407+
CgroupPermissions: "rwm",
408+
},
409+
}
410+
assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
411+
}

0 commit comments

Comments
 (0)