Skip to content

Commit

Permalink
fix(patch): apply image parse fix to v0.25.2 patch (#1208)
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Oct 15, 2024
1 parent 0db9ba6 commit 64c1b2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions internal/token/mint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 14 additions & 5 deletions internal/token/mint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 64c1b2d

Please sign in to comment.