summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-03-24 10:54:42 +0100
committerMatthew Heon <mheon@redhat.com>2021-03-29 13:27:33 -0400
commit43c772aa2910e7c3c3f839a29ec7dea632a0b300 (patch)
treed89cb03e8f66ee0a4a01dc557444d3d426064326
parent396a59b0229aae6f87cb18eb6d369087eefdaf57 (diff)
downloadpodman-43c772aa2910e7c3c3f839a29ec7dea632a0b300.tar.gz
podman-43c772aa2910e7c3c3f839a29ec7dea632a0b300.tar.bz2
podman-43c772aa2910e7c3c3f839a29ec7dea632a0b300.zip
libpod/image: unit tests: defer cleanup
Defer cleaning up the test artifacts as early as possible. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r--libpod/image/image_test.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go
index ed1d15ecc..df90c2db3 100644
--- a/libpod/image/image_test.go
+++ b/libpod/image/image_test.go
@@ -95,6 +95,8 @@ func TestImage_NewFromLocal(t *testing.T) {
// Need images to be present for this test
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
+ defer cleanup(workdir, ir)
+
ir.Eventer = events.NewNullEventer()
bb, err := ir.New(context.Background(), "docker.io/library/busybox:latest", "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil)
assert.NoError(t, err)
@@ -112,9 +114,6 @@ func TestImage_NewFromLocal(t *testing.T) {
assert.Equal(t, newImage.ID(), image.img.ID())
}
}
-
- // Shutdown the runtime and remove the temporary storage
- cleanup(workdir, ir)
}
// TestImage_New tests pulling the image by various names, tags, and from
@@ -127,13 +126,14 @@ func TestImage_New(t *testing.T) {
var names []string
workdir, err := mkWorkDir()
assert.NoError(t, err)
-
so := storage.StoreOptions{
RunRoot: workdir,
GraphRoot: workdir,
}
ir, err := NewImageRuntimeFromOptions(so)
assert.NoError(t, err)
+ defer cleanup(workdir, ir)
+
ir.Eventer = events.NewNullEventer()
// Build the list of pull names
names = append(names, bbNames...)
@@ -148,9 +148,6 @@ func TestImage_New(t *testing.T) {
err = newImage.Remove(context.Background(), false)
assert.NoError(t, err)
}
-
- // Shutdown the runtime and remove the temporary storage
- cleanup(workdir, ir)
}
// TestImage_MatchRepoTag tests the various inputs we need to match
@@ -163,13 +160,14 @@ func TestImage_MatchRepoTag(t *testing.T) {
//Set up
workdir, err := mkWorkDir()
assert.NoError(t, err)
-
so := storage.StoreOptions{
RunRoot: workdir,
GraphRoot: workdir,
}
ir, err := NewImageRuntimeFromOptions(so)
require.NoError(t, err)
+ defer cleanup(workdir, ir)
+
ir.Eventer = events.NewNullEventer()
newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, nil, util.PullImageMissing, nil)
require.NoError(t, err)
@@ -196,8 +194,6 @@ func TestImage_MatchRepoTag(t *testing.T) {
repoTag, err = newImage.MatchRepoTag("foo:bar")
require.NoError(t, err)
assert.Equal(t, "localhost/foo:bar", repoTag)
- // Shutdown the runtime and remove the temporary storage
- cleanup(workdir, ir)
}
// TestImage_RepoDigests tests RepoDigest generation.