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

Function TestDeviceParser

pkg/parse/parse_test.go:14–59  ·  view source on GitHub ↗

TestDeviceParser verifies the given device strings is parsed correctly

(t *testing.T)

Source from the content-addressed store, hash-verified

12
13// TestDeviceParser verifies the given device strings is parsed correctly
14func TestDeviceParser(t *testing.T) {
15 if runtime.GOOS != "linux" {
16 t.Skip("Devices is only supported on Linux")
17 }
18
19 // Test defaults
20 src, dest, permissions, err := Device("/dev/foo")
21 assert.NoError(t, err)
22 assert.Equal(t, src, "/dev/foo")
23 assert.Equal(t, dest, "/dev/foo")
24 assert.Equal(t, permissions, "rwm")
25
26 // Test defaults, different dest
27 src, dest, permissions, err = Device("/dev/foo:/dev/bar")
28 assert.NoError(t, err)
29 assert.Equal(t, src, "/dev/foo")
30 assert.Equal(t, dest, "/dev/bar")
31 assert.Equal(t, permissions, "rwm")
32
33 // Test fully specified
34 src, dest, permissions, err = Device("/dev/foo:/dev/bar:rm")
35 assert.NoError(t, err)
36 assert.Equal(t, src, "/dev/foo")
37 assert.Equal(t, dest, "/dev/bar")
38 assert.Equal(t, permissions, "rm")
39
40 // Test device, permissions
41 src, dest, permissions, err = Device("/dev/foo:rm")
42 assert.NoError(t, err)
43 assert.Equal(t, src, "/dev/foo")
44 assert.Equal(t, dest, "/dev/foo")
45 assert.Equal(t, permissions, "rm")
46
47 // test bogus permissions
48 _, _, _, err = Device("/dev/fuse1:BOGUS") //nolint
49 assert.Error(t, err)
50
51 _, _, _, err = Device("") //nolint
52 assert.Error(t, err)
53
54 _, _, _, err = Device("/dev/foo:/dev/bar:rm:") //nolint
55 assert.Error(t, err)
56
57 _, _, _, err = Device("/dev/foo::rm") //nolint
58 assert.Error(t, err)
59}
60
61func TestIsValidDeviceMode(t *testing.T) {
62 if runtime.GOOS != "linux" {

Callers

nothing calls this directly

Calls 2

DeviceFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…