diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2021-03-24 10:51:33 +0100 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2021-03-29 13:27:26 -0400 |
commit | 396a59b0229aae6f87cb18eb6d369087eefdaf57 (patch) | |
tree | 47488d495ad1b12083228c20d4f124358ee8be2e | |
parent | a01b387e8251bef5fc73f3e8ac72cc5db9ecea9e (diff) | |
download | podman-396a59b0229aae6f87cb18eb6d369087eefdaf57.tar.gz podman-396a59b0229aae6f87cb18eb6d369087eefdaf57.tar.bz2 podman-396a59b0229aae6f87cb18eb6d369087eefdaf57.zip |
libpod/image: unit tests: use `require.NoError`
In contrast to `assert.NoError`, `require.NoError` treats mismatches
fatally which in many cases is necessary to prevent subsequent checks
from segfaulting.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
-rw-r--r-- | libpod/image/image_test.go | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/libpod/image/image_test.go b/libpod/image/image_test.go index e2518b687..ed1d15ecc 100644 --- a/libpod/image/image_test.go +++ b/libpod/image/image_test.go @@ -14,6 +14,7 @@ import ( "github.com/containers/storage/pkg/reexec" "github.com/opencontainers/go-digest" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var ( @@ -107,7 +108,7 @@ func TestImage_NewFromLocal(t *testing.T) { assert.NoError(t, err) for _, name := range image.names { newImage, err := ir.NewFromLocal(name) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, newImage.ID(), image.img.ID()) } } @@ -142,7 +143,7 @@ func TestImage_New(t *testing.T) { // after the pull for _, img := range names { newImage, err := ir.New(context.Background(), img, "", "", writer, nil, SigningOptions{}, nil, util.PullImageMissing, nil) - assert.NoError(t, err) + require.NoError(t, err) assert.NotEqual(t, newImage.ID(), "") err = newImage.Remove(context.Background(), false) assert.NoError(t, err) @@ -168,14 +169,14 @@ func TestImage_MatchRepoTag(t *testing.T) { GraphRoot: workdir, } ir, err := NewImageRuntimeFromOptions(so) - assert.NoError(t, err) + require.NoError(t, err) ir.Eventer = events.NewNullEventer() newImage, err := ir.New(context.Background(), "busybox", "", "", os.Stdout, nil, SigningOptions{}, nil, util.PullImageMissing, nil) - assert.NoError(t, err) + require.NoError(t, err) err = newImage.TagImage("foo:latest") - assert.NoError(t, err) + require.NoError(t, err) err = newImage.TagImage("foo:bar") - assert.NoError(t, err) + require.NoError(t, err) // Tests start here. for _, name := range bbNames { @@ -188,12 +189,12 @@ func TestImage_MatchRepoTag(t *testing.T) { // foo should resolve to foo:latest repoTag, err := newImage.MatchRepoTag("foo") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "localhost/foo:latest", repoTag) // foo:bar should resolve to foo:bar repoTag, err = newImage.MatchRepoTag("foo:bar") - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "localhost/foo:bar", repoTag) // Shutdown the runtime and remove the temporary storage cleanup(workdir, ir) @@ -202,9 +203,7 @@ func TestImage_MatchRepoTag(t *testing.T) { // TestImage_RepoDigests tests RepoDigest generation. func TestImage_RepoDigests(t *testing.T) { dgst, err := digest.Parse("sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc") - if err != nil { - t.Fatal(err) - } + require.NoError(t, err) for _, tt := range []struct { name string @@ -236,10 +235,7 @@ func TestImage_RepoDigests(t *testing.T) { }, } actual, err := image.RepoDigests() - if err != nil { - t.Fatal(err) - } - + require.NoError(t, err) assert.Equal(t, test.expected, actual) image = &Image{ @@ -249,10 +245,7 @@ func TestImage_RepoDigests(t *testing.T) { }, } actual, err = image.RepoDigests() - if err != nil { - t.Fatal(err) - } - + require.NoError(t, err) assert.Equal(t, test.expected, actual) }) } |