From 0269da5c4e6e363910506b1d0de3c217a85259f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Wed, 9 Aug 2023 12:24:35 +0200 Subject: [PATCH] integration/tag: Use subtests and make parallel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski (cherry picked from commit 71da8c13e18db5770127ee532b8a47c6e3d4bc2b) Signed-off-by: Sebastiaan van Stijn --- integration/image/tag_test.go | 89 ++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/integration/image/tag_test.go b/integration/image/tag_test.go index a6b44d67e0..0eae263aa7 100644 --- a/integration/image/tag_test.go +++ b/integration/image/tag_test.go @@ -27,43 +27,60 @@ func TestTagUnprefixedRepoByNameOrName(t *testing.T) { assert.NilError(t, err) } -// ensure we don't allow the use of invalid repository names or tags; these tag operations should fail -// TODO (yongtang): Migrate to unit tests +// Ensure we don't allow the use of invalid repository names or tags; these tag operations should fail +// TODO(vvoland): Expected errors here are currently returned by the client. +// Consider moving/duplicating the check to the API side or +// migrating this into a client unit test. func TestTagInvalidReference(t *testing.T) { - defer setupTest(t)() + t.Cleanup(setupTest(t)) client := testEnv.APIClient() ctx := context.Background() invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "FOO/bar"} - for _, repo := range invalidRepos { - err := client.ImageTag(ctx, "busybox", repo) - assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) + repo := repo + t.Run("invalidRepo/"+repo, func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox", repo) + assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) + }) } longTag := testutil.GenerateRandomAlphaOnlyString(121) - invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag} - for _, repotag := range invalidTags { - err := client.ImageTag(ctx, "busybox", repotag) - assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) + repotag := repotag + t.Run("invalidTag/"+repotag, func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox", repotag) + assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) + }) } - // test repository name begin with '-' - err := client.ImageTag(ctx, "busybox:latest", "-busybox:test") - assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + t.Run("test repository name begin with '-'", func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox:latest", "-busybox:test") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + }) - // test namespace name begin with '-' - err = client.ImageTag(ctx, "busybox:latest", "-test/busybox:test") - assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + t.Run("test namespace name begin with '-'", func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox:latest", "-test/busybox:test") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + }) - // test index name begin with '-' - err = client.ImageTag(ctx, "busybox:latest", "-index:5000/busybox:test") - assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + t.Run("test index name begin with '-'", func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox:latest", "-index:5000/busybox:test") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) + }) +} - // test setting tag fails - err = client.ImageTag(ctx, "busybox:latest", "sha256:sometag") +func TestTagUsingDigestAlgorithmAsName(t *testing.T) { + defer setupTest(t)() + client := testEnv.APIClient() + ctx := context.Background() + err := client.ImageTag(ctx, "busybox:latest", "sha256:sometag") assert.Check(t, is.ErrorContains(err, "refusing to create an ambiguous tag using digest algorithm as name")) } @@ -76,8 +93,12 @@ func TestTagValidPrefixedRepo(t *testing.T) { validRepos := []string{"fooo/bar", "fooaa/test", "foooo:t", "HOSTNAME.DOMAIN.COM:443/foo/bar"} for _, repo := range validRepos { - err := client.ImageTag(ctx, "busybox", repo) - assert.NilError(t, err) + repo := repo + t.Run(repo, func(t *testing.T) { + t.Parallel() + err := client.ImageTag(ctx, "busybox", repo) + assert.NilError(t, err) + }) } } @@ -107,18 +128,20 @@ func TestTagOfficialNames(t *testing.T) { } for _, name := range names { - err := client.ImageTag(ctx, "busybox", name+":latest") - assert.NilError(t, err) + name := name + t.Run("tag from busybox to "+name, func(t *testing.T) { + err := client.ImageTag(ctx, "busybox", name+":latest") + assert.NilError(t, err) - // ensure we don't have multiple tag names. - insp, _, err := client.ImageInspectWithRaw(ctx, "busybox") - assert.NilError(t, err) - assert.Assert(t, !is.Contains(insp.RepoTags, name)().Success()) - } + // ensure we don't have multiple tag names. + insp, _, err := client.ImageInspectWithRaw(ctx, "busybox") + assert.NilError(t, err) + // TODO(vvoland): Not sure what's actually being tested here. Is is still doing anything useful? + assert.Assert(t, !is.Contains(insp.RepoTags, name)().Success()) - for _, name := range names { - err := client.ImageTag(ctx, name+":latest", "fooo/bar:latest") - assert.NilError(t, err) + err = client.ImageTag(ctx, name+":latest", "test-tag-official-names/foobar:latest") + assert.NilError(t, err) + }) } }