-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into pipelinespec
- Loading branch information
Showing
141 changed files
with
2,593 additions
and
2,450 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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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,18 @@ | ||
package main | ||
|
||
import ( | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
) | ||
|
||
// GetDigest returns the digest of an OCI image index. If there is only one image in the index, the | ||
// digest of the image is returned; otherwise, the digest of the whole index is returned. | ||
func GetDigest(ii v1.ImageIndex) (v1.Hash, error) { | ||
im, err := ii.IndexManifest() | ||
if err != nil { | ||
return v1.Hash{}, err | ||
} | ||
if len(im.Manifests) == 1 { | ||
return im.Manifests[0].Digest, nil | ||
} | ||
return ii.Digest() | ||
} |
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,65 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"github.com/google/go-containerregistry/pkg/v1/empty" | ||
"github.com/google/go-containerregistry/pkg/v1/random" | ||
) | ||
|
||
func TestGetDigest(t *testing.T) { | ||
mustGetIndex := func(ii v1.ImageIndex, err error) v1.ImageIndex { | ||
if err != nil { | ||
t.Fatalf("must get image: %s", err) | ||
} | ||
return ii | ||
} | ||
mustGetManifest := func(im *v1.IndexManifest, err error) *v1.IndexManifest { | ||
if err != nil { | ||
t.Fatalf("must get manifest: %s", err) | ||
} | ||
return im | ||
} | ||
mustGetDigest := func(h v1.Hash, err error) v1.Hash { | ||
if err != nil { | ||
t.Fatalf("must get digest: %s", err) | ||
} | ||
return h | ||
} | ||
indexSingleImage := mustGetIndex(random.Index(1024, 4, 1)) | ||
indexMultipleImages := mustGetIndex(random.Index(1024, 4, 4)) | ||
tests := []struct { | ||
name string | ||
index v1.ImageIndex | ||
expected v1.Hash | ||
}{ | ||
{ | ||
name: "empty index", | ||
index: empty.Index, | ||
expected: mustGetDigest(empty.Index.Digest()), | ||
}, | ||
{ | ||
name: "index with single image", | ||
index: indexSingleImage, | ||
expected: mustGetManifest(indexSingleImage.IndexManifest()).Manifests[0].Digest, | ||
}, | ||
{ | ||
name: "index with multiple images", | ||
index: indexMultipleImages, | ||
expected: mustGetDigest(indexMultipleImages.Digest()), | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
digest, err := GetDigest(test.index) | ||
if err != nil { | ||
t.Fatalf("cannot get digest: %s", err) | ||
} | ||
if diff := cmp.Diff(digest, test.expected); diff != "" { | ||
t.Errorf("get digest: -want +got: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.