-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added regex and cleanup string algo for repo based tag generator
Signed-off-by: rcmadhankumar <[email protected]>
- Loading branch information
1 parent
8455c2f
commit 893073b
Showing
2 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2023 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package util_test | ||
|
||
import ( | ||
"testing" | ||
|
||
regname "github.com/google/go-containerregistry/pkg/name" | ||
"github.com/stretchr/testify/require" | ||
"github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/imagedigest" | ||
util "github.com/vmware-tanzu/carvel-imgpkg/pkg/imgpkg/internal/util" | ||
) | ||
|
||
type testDescribe struct { | ||
description string | ||
origRef string | ||
expectedTag string | ||
} | ||
|
||
func TestGenerateTagRepobasedgenerator(t *testing.T) { | ||
allTests := []testDescribe{ | ||
{ | ||
description: "OrigRef starts with -", | ||
origRef: "index.docker.io/_test-repo/simple-app-test@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c", | ||
expectedTag: "_test-repo-simple-app-test-sha256-61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c.imgpkg", | ||
}, | ||
{ | ||
description: "OrigRef starts with *-", | ||
origRef: "index.docker.io/*-test-repo/simple-app-test@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c", | ||
expectedTag: "test-repo-simple-app-test-sha256-61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c.imgpkg", | ||
}, | ||
{ | ||
description: "OrigRef starts with .", | ||
origRef: "index.docker.io/.test-repo/simple-app-test@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c", | ||
expectedTag: "test-repo-simple-app-test-sha256-61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c.imgpkg", | ||
}, | ||
{ | ||
description: "OrigRef contains 100+ characters", | ||
origRef: "index.docker.io/test-path/sample-path/verification-path/sample-path/test-repo/test-repo/simple-app-test@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c", | ||
expectedTag: "h-sample-path-test-repo-test-repo-simple-app-test-sha256-61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c.imgpkg", | ||
}, | ||
{ | ||
description: "OrigRef contains 100+ characters with special characters @#$%^&*()", | ||
origRef: "index.docker.io/tes%t-path/sample-path/verific&*ation-path*&^%$/sample-pa(th/test-repo/t)est-repo/simple-app-test@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c", | ||
expectedTag: "h-sample-path-test-repo-test-repo-simple-app-test-sha256-61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c.imgpkg", | ||
}, | ||
} | ||
|
||
for _, test := range allTests { | ||
t.Run(test.description, func(t *testing.T) { | ||
digestWrap := imagedigest.DigestWrap{} | ||
imgIdxRef := "index.docker.io/test-repo/tert-src-repo@sha256:61cb2e3a8522bfd9d4b6219cb9e382df151ba6d4fcc4c96f870ee4e1cffbbf9c" | ||
digestWrap.DigestWrap(imgIdxRef, test.origRef) | ||
importRepo, err := regname.NewRepository("import-registry/dst-repo") | ||
require.NoError(t, err) | ||
tagGen := util.RepoBasedTagGenerator{} | ||
tag, err := tagGen.GenerateTag(digestWrap, importRepo) | ||
require.NoError(t, err) | ||
require.Equal(t, test.expectedTag, tag.TagStr()) | ||
require.LessOrEqual(t, len(tag.TagStr()), 128) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters