MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestRunVolume

Function TestRunVolume

cmd/nerdctl/container/container_run_mount_linux_test.go:41–91  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39)
40
41func TestRunVolume(t *testing.T) {
42 t.Parallel()
43 base := testutil.NewBase(t)
44 tID := testutil.Identifier(t)
45 rwDir, err := os.MkdirTemp(t.TempDir(), "rw")
46 if err != nil {
47 t.Fatal(err)
48 }
49 roDir, err := os.MkdirTemp(t.TempDir(), "ro")
50 if err != nil {
51 t.Fatal(err)
52 }
53 rwVolName := tID + "-rw"
54 roVolName := tID + "-ro"
55 for _, v := range []string{rwVolName, roVolName} {
56 defer base.Cmd("volume", "rm", "-f", v).Run()
57 base.Cmd("volume", "create", v).AssertOK()
58 }
59
60 containerName := tID
61 defer base.Cmd("rm", "-f", containerName).AssertOK()
62 base.Cmd("run",
63 "-d",
64 "--name", containerName,
65 "-v", fmt.Sprintf("%s:/mnt1", rwDir),
66 "-v", fmt.Sprintf("%s:/mnt2:ro", roDir),
67 "-v", fmt.Sprintf("%s:/mnt3", rwVolName),
68 "-v", fmt.Sprintf("%s:/mnt4:ro", roVolName),
69 testutil.AlpineImage,
70 "top",
71 ).AssertOK()
72 base.Cmd("exec", containerName, "sh", "-exc", "echo -n str1 > /mnt1/file1").AssertOK()
73 base.Cmd("exec", containerName, "sh", "-exc", "echo -n str2 > /mnt2/file2").AssertFail()
74 base.Cmd("exec", containerName, "sh", "-exc", "echo -n str3 > /mnt3/file3").AssertOK()
75 base.Cmd("exec", containerName, "sh", "-exc", "echo -n str4 > /mnt4/file4").AssertFail()
76 base.Cmd("rm", "-f", containerName).AssertOK()
77 base.Cmd("run",
78 "--rm",
79 "-v", fmt.Sprintf("%s:/mnt1", rwDir),
80 "-v", fmt.Sprintf("%s:/mnt3", rwVolName),
81 testutil.AlpineImage,
82 "cat", "/mnt1/file1", "/mnt3/file3",
83 ).AssertOutExactly("str1str3")
84 base.Cmd("run",
85 "--rm",
86 "-v", fmt.Sprintf("%s:/mnt3/mnt1", rwDir),
87 "-v", fmt.Sprintf("%s:/mnt3", rwVolName),
88 testutil.AlpineImage,
89 "cat", "/mnt3/mnt1/file1", "/mnt3/file3",
90 ).AssertOutExactly("str1str3")
91}
92
93func TestRunAnonymousVolume(t *testing.T) {
94 t.Parallel()

Callers

nothing calls this directly

Calls 8

CmdMethod · 0.95
NewBaseFunction · 0.92
IdentifierFunction · 0.92
AssertOKMethod · 0.80
AssertFailMethod · 0.80
AssertOutExactlyMethod · 0.80
TempDirMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…