From 64c1b2d5979dea375ef2939d692944b317fca4af Mon Sep 17 00:00:00 2001 From: Easton Crupper <65553218+ecrupper@users.noreply.github.com> Date: Tue, 15 Oct 2024 10:15:54 -0400 Subject: [PATCH] fix(patch): apply image parse fix to v0.25.2 patch (#1208) --- internal/token/mint.go | 4 ++++ internal/token/mint_test.go | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/internal/token/mint.go b/internal/token/mint.go index 4ab6ed4f7..8fe074aab 100644 --- a/internal/token/mint.go +++ b/internal/token/mint.go @@ -223,6 +223,10 @@ func imageParse(image string) (string, string, error) { return image, "latest", nil case 2: return parts[0], parts[1], nil + case 3: + _parts := strings.Split(parts[1]+parts[2], "@") + + return parts[0], _parts[0], nil default: return "", "", fmt.Errorf("invalid image format: %s", image) } diff --git a/internal/token/mint_test.go b/internal/token/mint_test.go index 7ec01bc34..a949b4602 100644 --- a/internal/token/mint_test.go +++ b/internal/token/mint_test.go @@ -24,6 +24,15 @@ func Test_imageParse(t *testing.T) { wantTag: "1.20", wantErr: false, }, + { + name: "image with tag and sha", + args: args{ + image: "alpine:1.20@sha:fc0d4410fd2343cf6f7a75d5819001a34ca3b549fbab0c231b7aab49b57e9e43", + }, + wantName: "alpine", + wantTag: "1.20", + wantErr: false, + }, { name: "image without latest tag", args: args{ @@ -45,16 +54,16 @@ func Test_imageParse(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, got1, err := imageParse(tt.args.image) + gotName, gotTag, err := imageParse(tt.args.image) if (err != nil) != tt.wantErr { t.Errorf("imageParse() error = %v, wantErr %v", err, tt.wantErr) return } - if got != tt.wantName { - t.Errorf("imageParse() got = %v, wantName %v", got, tt.wantName) + if gotName != tt.wantName { + t.Errorf("imageParse() got = %v, wantName %v", gotName, tt.wantName) } - if got1 != tt.wantTag { - t.Errorf("imageParse() got1 = %v, wantName %v", got1, tt.wantTag) + if gotTag != tt.wantTag { + t.Errorf("imageParse() got1 = %v, wantName %v", gotTag, tt.wantTag) } }) }