mirror of https://github.com/knative/func.git
Fix appending SHA256 hash to image reference in ImageWithDigest (#1784)
This commit is contained in:
parent
75a8b8991d
commit
109e6b6be8
|
@ -472,6 +472,12 @@ func (f Function) ImageWithDigest() string {
|
|||
return f.Image
|
||||
}
|
||||
|
||||
// Return image with new Digest if image already contains SHA256 Digest
|
||||
shaIndex := strings.Index(f.Image, "@sha256:")
|
||||
if shaIndex > 0 {
|
||||
return f.Image[:shaIndex] + "@" + f.ImageDigest
|
||||
}
|
||||
|
||||
lastSlashIdx := strings.LastIndexAny(f.Image, "/")
|
||||
imageAsBytes := []byte(f.Image)
|
||||
|
||||
|
|
|
@ -105,6 +105,16 @@ func TestFunction_ImageWithDigest(t *testing.T) {
|
|||
fields: fields{Image: "bar:latest", ImageDigest: "42"},
|
||||
want: "bar@42",
|
||||
},
|
||||
{
|
||||
name: "Full path with port and SHA256 Digest",
|
||||
fields: fields{Image: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42", ImageDigest: "sha256:42"},
|
||||
want: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42",
|
||||
},
|
||||
{
|
||||
name: "Full path with port and SHA256 Digest with empty ImageDigest",
|
||||
fields: fields{Image: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42", ImageDigest: ""},
|
||||
want: "image-registry.openshift-image-registry.svc.cluster.local:50000/default/bar@sha256:42",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue