Skip to content

Commit dbc0540

Browse files
committed
Fix TestLoadStdinFromPipe: do not leak test images breaking tests using prune
Signed-off-by: apostasie <[email protected]>
1 parent 51258bd commit dbc0540

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

cmd/nerdctl/image/image_load_linux_test.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,35 @@ import (
3232
func TestLoadStdinFromPipe(t *testing.T) {
3333
t.Parallel()
3434
base := testutil.NewBase(t)
35-
35+
img := testutil.Identifier(t)
3636
tmp := t.TempDir()
37-
img := testutil.Identifier(t) + "image"
38-
base.Cmd("pull", testutil.CommonImage).AssertOK()
39-
base.Cmd("tag", testutil.CommonImage, img).AssertOK()
40-
base.Cmd("save", img, "-o", filepath.Join(tmp, "common.tar")).AssertOK()
41-
base.Cmd("rmi", "-f", img).AssertOK()
42-
loadCmd := strings.Join(base.Cmd("load").Command, " ")
4337
output := filepath.Join(tmp, "output")
4438

39+
setup := func() {
40+
base.Cmd("pull", testutil.CommonImage).AssertOK()
41+
base.Cmd("tag", testutil.CommonImage, img).AssertOK()
42+
base.Cmd("save", img, "-o", filepath.Join(tmp, "common.tar")).AssertOK()
43+
base.Cmd("rmi", "-f", img).AssertOK()
44+
}
45+
46+
tearDown := func() {
47+
base.Cmd("rmi", "-f", img).AssertOK()
48+
}
49+
50+
t.Cleanup(tearDown)
51+
tearDown()
52+
53+
setup()
54+
55+
loadCmd := strings.Join(base.Cmd("load").Command, " ")
4556
combined, err := exec.Command("sh", "-euxc", fmt.Sprintf("`cat %s/common.tar | %s > %s`", tmp, loadCmd, output)).CombinedOutput()
4657
assert.NilError(t, err, "failed with error %s and combined output is %s", err, string(combined))
58+
4759
fb, err := os.ReadFile(output)
4860
assert.NilError(t, err)
4961

5062
assert.Assert(t, strings.Contains(string(fb), fmt.Sprintf("Loaded image: %s:latest", img)))
51-
base.Cmd("images").AssertOutContains(testutil.ImageRepo(testutil.CommonImage))
63+
base.Cmd("images").AssertOutContains(img)
5264
}
5365

5466
func TestLoadStdinEmpty(t *testing.T) {

0 commit comments

Comments
 (0)