MCPcopy
hub / github.com/containerd/containerd / TestLoopbackMount

Function TestLoopbackMount

core/mount/manager/manager_linux_test.go:39–105  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37)
38
39func TestLoopbackMount(t *testing.T) {
40 testutil.RequiresRoot(t)
41 ctx := logtest.WithT(context.Background(), t)
42 ctx = namespaces.WithNamespace(ctx, "test")
43 td := t.TempDir()
44 metadb := filepath.Join(td, "mounts.db")
45 targetdir := filepath.Join(td, "m")
46 db, err := bolt.Open(metadb, 0600, nil)
47 if err != nil {
48 t.Fatal(err)
49 }
50
51 a := fstest.Apply(
52 fstest.CreateFile("/foo", []byte("foo\n"), 0777),
53 fstest.CreateDir("/a", 0755),
54 fstest.CreateDir("/a/b", 0755),
55 fstest.CreateDir("/a/b/c", 0755),
56 )
57
58 source, err := initalizeBlockDevice(td, a)
59 if err != nil {
60 t.Fatal(err)
61 }
62 mounts := []mount.Mount{
63 {
64 Type: "loop",
65 Source: source,
66 Options: []string{},
67 },
68 {
69 Type: "format/ext4",
70 Source: "{{ mount 0 }}", // previous mount
71 Options: []string{},
72 },
73 }
74
75 m, err := NewManager(db, targetdir, WithMountHandler("loop", mount.LoopbackHandler()))
76 require.NoError(t, err)
77 ainfo, err := m.Activate(ctx, "id1", mounts)
78 require.NoError(t, err)
79 defer func() {
80 assert.NoError(t, m.Deactivate(ctx, "id1"))
81 }()
82
83 tm, err := os.MkdirTemp(td, "test-mount-")
84 if err != nil {
85 t.Fatal(err)
86 }
87
88 actual, err := os.MkdirTemp(td, "actual-")
89 if err != nil {
90 t.Fatal(err)
91 }
92
93 if err := a.Apply(actual); err != nil {
94 t.Fatal(err)
95 }
96

Callers

nothing calls this directly

Calls 13

ActivateMethod · 0.95
DeactivateMethod · 0.95
RequiresRootFunction · 0.92
WithNamespaceFunction · 0.92
LoopbackHandlerFunction · 0.92
AllFunction · 0.92
UnmountFunction · 0.92
initalizeBlockDeviceFunction · 0.85
WithMountHandlerFunction · 0.85
FatalMethod · 0.80
NewManagerFunction · 0.70
ApplyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…