Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions registry-scanner/pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func (img *ContainerImage) String() string {
func (img *ContainerImage) GetFullNameWithoutTag() string {
str := ""
if img.RegistryURL != "" {
str += img.RegistryURL + "/"
if !strings.HasPrefix(img.ImageName, img.RegistryURL+"/") {
str += img.RegistryURL + "/"
}
}
str += img.ImageName
return str
Expand All @@ -91,7 +93,9 @@ func (img *ContainerImage) GetFullNameWithoutTag() string {
func (img *ContainerImage) GetFullNameWithTag() string {
str := ""
if img.RegistryURL != "" {
str += img.RegistryURL + "/"
if !strings.HasPrefix(img.ImageName, img.RegistryURL+"/") {
str += img.RegistryURL + "/"
}
}
str += img.ImageName
if img.ImageTag != nil {
Expand Down
7 changes: 7 additions & 0 deletions registry-scanner/pkg/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ func Test_ParseImageTags(t *testing.T) {
assert.Equal(t, "0.1", image.ImageTag.TagName)
assert.Equal(t, "docker.io/jannfis/test-image:0.1", image.GetFullNameWithTag())
assert.Equal(t, "docker.io/jannfis/test-image", image.GetFullNameWithoutTag())

// if the image name starts with registryURL, GetFullNameWithoutTag and GetFullNameWithTag
// should return the correct full image name without repeating registryURL.
// Wrong full image name: docker.io/docker.io/jannfis/test-image
image.ImageName = "docker.io/jannfis/test-image"
assert.Equal(t, "docker.io/jannfis/test-image:0.1", image.GetFullNameWithTag())
assert.Equal(t, "docker.io/jannfis/test-image", image.GetFullNameWithoutTag())
})

t.Run("Parse valid image name with digest tag", func(t *testing.T) {
Expand Down