MCPcopy
hub / github.com/containerd/containerd / TestMountAtRuntime

Function TestMountAtRuntime

integration/client/mount_manager_linux_test.go:66–189  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestMountAtRuntime(t *testing.T) {
67 client, err := newClient(t, address)
68 if err != nil {
69 t.Fatal(err)
70 }
71 defer client.Close()
72
73 var (
74 ctx, cancel = testContext(t)
75 id1 = fmt.Sprintf("%s-1", t.Name())
76 id2 = fmt.Sprintf("%s-2", t.Name())
77 testDev = createImgFile(t, "test-dev.img")
78 workDir = filepath.Join(t.TempDir(), "work")
79 )
80 defer cancel()
81
82 require.NoError(t, os.MkdirAll(workDir, 0755))
83
84 ctx, done, err := client.WithLease(ctx)
85 require.NoError(t, err)
86 defer done(ctx)
87
88 img, err := client.GetImage(ctx, testImage)
89 require.NoError(t, err)
90
91 snapshotter := client.SnapshotService(defaults.DefaultSnapshotter)
92 diffIDs, err := img.RootFS(ctx)
93 require.NoError(t, err)
94
95 mnt, err := snapshotter.View(ctx, id1, identity.ChainID(diffIDs).String())
96 require.NoError(t, err)
97 if len(mnt) > 1 {
98 t.Skipf("Test can only be run with single mount")
99 }
100 m := append(mnt, mount.Mount{
101 Type: "xfs",
102 Source: testDev,
103 Options: []string{"loop"},
104 }, mount.Mount{
105 Type: "format/overlay",
106 Source: "overlay",
107 Options: []string{"lowerdir={{ mount 0 }}", "upperdir={{ mount 1 }}/root1", "workdir={{ mount 1 }}/work", "index=off"},
108 })
109
110 container1, err := client.NewContainer(ctx, id1, containerd.WithNewSpec(withImage(img, "sh", "-c", `echo -n 'Test mount at runtime'> /etc/test-name.txt`)))
111 require.NoError(t, err)
112 defer func() { assert.NoError(t, container1.Delete(ctx)) }()
113
114 task, err := container1.NewTask(ctx, empty(), containerd.WithRootFS(m))
115 require.NoError(t, err)
116 defer func() {
117 if task != nil {
118 task.Delete(ctx)
119 }
120 }()
121
122 info, err := client.MountManager().Info(ctx, id1)
123 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
newClientFunction · 0.85
testContextFunction · 0.85
createImgFileFunction · 0.85
withImageFunction · 0.85
emptyFunction · 0.85
FatalMethod · 0.80
MountManagerMethod · 0.80
CopyMethod · 0.80
newDirectIOFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…