MCPcopy
hub / github.com/containerd/containerd / TestMkdirHandler

Function TestMkdirHandler

core/mount/manager/mkdir_linux_test.go:34–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestMkdirHandler(t *testing.T) {
35 ctx := logtest.WithT(context.Background(), t)
36 ctx = namespaces.WithNamespace(ctx, "test")
37 td := t.TempDir()
38
39 luid := os.Getuid()
40 lgid := os.Getgid()
41 testmode := os.FileMode(0751)
42
43 root := filepath.Join(td, "root")
44 if err := os.MkdirAll(root, 0775); err != nil {
45 t.Fatal(err)
46 }
47 sourcedir := filepath.Join(root, "m")
48
49 r, err := os.OpenRoot(root)
50 if err != nil {
51 t.Fatal(err)
52 }
53 mh := mkdir{
54 rootMap: map[string]*os.Root{
55 root: r,
56 },
57 }
58
59 m := mount.Mount{
60 Type: "mkdir/overlay",
61 Source: "overlay",
62 Options: []string{
63 fmt.Sprintf("X-containerd.mkdir.path=%s:%o:%d:%d", sourcedir, testmode, luid, lgid),
64 },
65 }
66
67 _, err = mh.Transform(ctx, m, nil)
68 if err != nil {
69 t.Fatal(err)
70 }
71
72 fi, err := os.Stat(sourcedir)
73 if err != nil {
74 t.Fatal(err)
75 }
76 if !fi.IsDir() {
77 t.Fatalf("expected directory")
78 }
79 if fi.Mode().Perm() != testmode {
80 t.Fatalf("expected mode 0775 got %o", fi.Mode().Perm())
81 }
82 sys := fi.Sys().(*syscall.Stat_t)
83 if int(sys.Uid) != luid {
84 t.Fatalf("expected uid 1000 got %d", sys.Uid)
85 }
86 if int(sys.Gid) != lgid {
87 t.Fatalf("expected gid 1000 got %d", sys.Gid)
88 }
89
90 m.Options = append(m.Options, fmt.Sprintf("X-containerd.mkdir.path=%s", filepath.Join(td, "notinroot")))
91 _, err = mh.Transform(ctx, m, nil)

Callers

nothing calls this directly

Calls 8

TransformMethod · 0.95
WithNamespaceFunction · 0.92
FatalMethod · 0.80
MkdirAllMethod · 0.65
StatMethod · 0.65
IsDirMethod · 0.45
ModeMethod · 0.45
SysMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…