Skip to content

Commit 8e888f0

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

File tree

1 file changed

+32
-70
lines changed

1 file changed

+32
-70
lines changed

cmd/nerdctl/container/container_inspect_linux_test.go

Lines changed: 32 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package container
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"strings"
2223
"testing"
@@ -251,7 +252,6 @@ func TestContainerInspectHostConfig(t *testing.T) {
251252
"--read-only",
252253
"--shm-size", "256m",
253254
"--uts", "host",
254-
"--device", "/dev/null:/dev/null",
255255
"--sysctl", "net.core.somaxconn=1024",
256256
"--runtime", "io.containerd.runc.v2",
257257
testutil.AlpineImage, "sleep", "infinity").AssertOK()
@@ -277,11 +277,6 @@ func TestContainerInspectHostConfig(t *testing.T) {
277277
assert.Equal(t, true, inspect.HostConfig.ReadonlyRootfs)
278278
assert.Equal(t, "host", inspect.HostConfig.UTSMode)
279279
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)
285280
}
286281

287282
func TestContainerInspectHostConfigDefaults(t *testing.T) {
@@ -305,19 +300,14 @@ func TestContainerInspectHostConfigDefaults(t *testing.T) {
305300
assert.Equal(t, "private", inspect.HostConfig.IpcMode)
306301
assert.Equal(t, "", inspect.HostConfig.LogConfig.Driver)
307302
assert.Equal(t, int64(0), inspect.HostConfig.Memory)
308-
t.Logf("inspect.HostConfig.Memory in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.Memory)
309303
assert.Equal(t, int64(0), inspect.HostConfig.MemorySwap)
310-
t.Logf("inspect.HostConfig.MemorySwap in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.MemorySwap)
311304
assert.Equal(t, bool(false), inspect.HostConfig.OomKillDisable)
312-
t.Logf("inspect.HostConfig.OomKillDisable in TestContainerInspectHostConfigDefaults: %+v", inspect.HostConfig.OomKillDisable)
313305
assert.Equal(t, bool(false), inspect.HostConfig.ReadonlyRootfs)
314306
assert.Equal(t, "", inspect.HostConfig.UTSMode)
315307
assert.Equal(t, int64(67108864), inspect.HostConfig.ShmSize)
316308
assert.Equal(t, "runc", inspect.HostConfig.Runtime)
317309
assert.Equal(t, 0, len(inspect.HostConfig.Sysctls))
318310
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))
321311
}
322312

323313
func TestContainerInspectHostConfigDNS(t *testing.T) {
@@ -406,62 +396,34 @@ func TestContainerInspectHostConfigPIDDefaults(t *testing.T) {
406396
assert.Equal(t, "", inspect.HostConfig.PidMode)
407397
}
408398

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-
// }
399+
func TestContainerInspectDevices(t *testing.T) {
400+
testContainer := testutil.Identifier(t)
401+
402+
base := testutil.NewBase(t)
403+
defer base.Cmd("rm", "-f", testContainer).Run()
404+
405+
// Run a container with various advanced HostConfig options
406+
base.Cmd("run", "-d", "--name", testContainer,
407+
"--device", "/dev/null:/dev/null",
408+
testutil.AlpineImage, "sleep", "infinity").AssertOK()
409+
410+
inspect := base.InspectContainer(testContainer)
411+
412+
// Check Devices
413+
expectedDevices := []dockercompat.DeviceMapping{
414+
{
415+
PathOnHost: "/dev/null",
416+
PathInContainer: "/dev/null",
417+
CgroupPermissions: "rwm",
418+
},
419+
}
420+
assert.DeepEqual(t, expectedDevices, inspect.HostConfig.Devices)
421+
422+
// Log the entire HostConfig for debugging
423+
hostConfigJSON, err := json.MarshalIndent(inspect.HostConfig, "", " ")
424+
if err != nil {
425+
t.Errorf("Failed to marshal HostConfig: %v", err)
426+
} else {
427+
t.Logf("HostConfig in TestContainerInspectDevices:\n%s", string(hostConfigJSON))
428+
}
429+
}

0 commit comments

Comments
 (0)