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

Function TestZstdCommit

cmd/nerdctl/container/container_commit_test.go:94–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

92}
93
94func TestZstdCommit(t *testing.T) {
95 testCase := nerdtest.Setup()
96 testCase.Require = require.All(
97 // FIXME: Docker does not support compression
98 require.Not(nerdtest.Docker),
99 nerdtest.ContainerdVersion("2.0.0"),
100 nerdtest.CGroup,
101 )
102 testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
103 helpers.Anyhow("rm", "-f", data.Identifier())
104 helpers.Anyhow("rmi", "-f", data.Identifier("image"))
105 }
106 testCase.Setup = func(data test.Data, helpers test.Helpers) {
107 identifier := data.Identifier()
108 helpers.Ensure("run", "-d", "--name", identifier, testutil.CommonImage, "sleep", nerdtest.Infinity)
109 nerdtest.EnsureContainerStarted(helpers, identifier)
110 helpers.Ensure("exec", identifier, "sh", "-euxc", `echo hello-test-commit > /foo`)
111 helpers.Ensure("commit", identifier, data.Identifier("image"), "--compression=zstd")
112 data.Labels().Set("image", data.Identifier("image"))
113 }
114
115 testCase.SubTests = []*test.Case{
116 {
117 Description: "verify zstd has been used",
118 Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
119 return helpers.Command("image", "inspect", "--mode=native", data.Labels().Get("image"))
120 },
121 Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
122 return &test.Expected{
123 ExitCode: 0,
124 Output: expect.JSON([]native.Image{}, func(images []native.Image, t tig.T) {
125 assert.Equal(t, len(images), 1)
126 assert.Equal(helpers.T(), images[0].Manifest.Layers[len(images[0].Manifest.Layers)-1].MediaType, "application/vnd.docker.image.rootfs.diff.tar.zstd")
127 }),
128 }
129 },
130 },
131 {
132 Description: "verify the image is working",
133 Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
134 return helpers.Command("run", "--rm", data.Labels().Get("image"), "sh", "-c", "--", "cat /foo")
135 },
136 Expected: test.Expects(0, nil, expect.Equals("hello-test-commit\n")),
137 },
138 }
139
140 testCase.Run(t)
141}

Callers

nothing calls this directly

Calls 12

SetupFunction · 0.92
ContainerdVersionFunction · 0.92
EnsureContainerStartedFunction · 0.92
AnyhowMethod · 0.65
IdentifierMethod · 0.65
EnsureMethod · 0.65
SetMethod · 0.65
LabelsMethod · 0.65
CommandMethod · 0.65
GetMethod · 0.65
TMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…