Skip to content

Commit 819768e

Browse files
test: address review feedback on container_create migration
Capture the start -a output and assert the passed MAC is absent for the none-network case, instead of only checking the exit code. Use data.Temp().Save for the Dockerfile instead of os.WriteFile, and drop the manual builder prune --all --force which the Build requirement deliberately omits to keep build tests parallelizable. Signed-off-by: Ogulcan Aydogan <ogulcanaydogan@hotmail.com>
1 parent a271d8b commit 819768e

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

cmd/nerdctl/container/container_create_linux_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ func TestCreateWithMACAddress(t *testing.T) {
146146
return &test.Expected{
147147
ExitCode: expect.ExitCodeSuccess,
148148
Output: func(stdout string, t tig.T) {
149-
helpers.Ensure("start", "-a", data.Identifier())
149+
startOut := helpers.Capture("start", "-a", data.Identifier())
150+
assert.Assert(t, !strings.Contains(startOut, data.Labels().Get(macAddressKey)),
151+
fmt.Sprintf("expected start output to not contain MAC %q: %q", data.Labels().Get(macAddressKey), startOut))
150152
},
151153
}
152154
},
@@ -441,8 +443,7 @@ func TestCreateFromOCIArchive(t *testing.T) {
441443

442444
testCase.Setup = func(data test.Data, helpers test.Helpers) {
443445
dockerfile := fmt.Sprintf("FROM %s\nCMD [\"echo\", \"%s\"]", testutil.CommonImage, sentinel)
444-
err := os.WriteFile(filepath.Join(data.Temp().Path(), "Dockerfile"), []byte(dockerfile), 0644)
445-
assert.NilError(helpers.T(), err)
446+
data.Temp().Save(dockerfile, "Dockerfile")
446447

447448
imageName := data.Identifier("image") + ":latest"
448449
tarPath := data.Temp().Path("image.tar")
@@ -458,7 +459,6 @@ func TestCreateFromOCIArchive(t *testing.T) {
458459
testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
459460
helpers.Anyhow("rm", "-f", data.Identifier())
460461
helpers.Anyhow("rmi", "-f", data.Labels().Get("imageName"))
461-
helpers.Anyhow("builder", "prune", "--all", "--force")
462462
}
463463
testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
464464
return helpers.Command("start", "--attach", data.Identifier())

0 commit comments

Comments
 (0)