MCPcopy Create free account
hub / github.com/containers/common / TestDeviceFromPath

Function TestDeviceFromPath

pkg/parse/parse_test.go:85–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestDeviceFromPath(t *testing.T) {
86 if runtime.GOOS != "linux" {
87 t.Skip("Devices is only supported on Linux")
88 }
89 // Path is valid
90 info, err := os.Stat("/dev/null")
91 assert.NoError(t, err)
92
93 var UID uint32
94 var GID uint32
95 if stat, ok := info.Sys().(*syscall.Stat_t); ok {
96 UID = stat.Uid
97 GID = stat.Gid
98 }
99 dev, err := DeviceFromPath("/dev/null")
100 assert.NoError(t, err)
101 assert.Equal(t, len(dev), 1)
102 assert.Equal(t, dev[0].Major, int64(1))
103 assert.Equal(t, dev[0].Minor, int64(3))
104 assert.Equal(t, string(dev[0].Permissions), "rwm")
105 assert.Equal(t, dev[0].Uid, UID)
106 assert.Equal(t, dev[0].Gid, GID)
107
108 // Path does not exists
109 _, err = DeviceFromPath("/dev/BOGUS")
110 assert.Error(t, err)
111
112 // Path is a directory of devices
113 _, err = DeviceFromPath("/dev/pts")
114 assert.NoError(t, err)
115
116 // path of directory has no device
117 _, err = DeviceFromPath("/etc/passwd")
118 assert.Error(t, err)
119}

Callers

nothing calls this directly

Calls 3

DeviceFromPathFunction · 0.85
StatMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…