Expose ParsePlatform (#45)

This commit is contained in:
James Carnegie
2024-05-31 11:02:14 +01:00
committed by GitHub
parent a334599635
commit c8c148c70a
3 changed files with 8 additions and 8 deletions

View File

@@ -20,9 +20,9 @@ import (
"github.com/pkg/errors"
)
// parsePlatform parses the provided platform string or attempts to obtain
// ParsePlatform parses the provided platform string or attempts to obtain
// the platform of the current host system
func parsePlatform(platformStr string) (*v1.Platform, error) {
func ParsePlatform(platformStr string) (*v1.Platform, error) {
if platformStr == "" {
cdp := platforms.Normalize(platforms.DefaultSpec())
if cdp.OS != "windows" {
@@ -106,7 +106,7 @@ type OCILayoutResolver struct {
}
func NewOCILayoutAttestationResolver(path string, platform string) (*OCILayoutResolver, error) {
p, err := parsePlatform(platform)
p, err := ParsePlatform(platform)
if err != nil {
return nil, err
}
@@ -202,7 +202,7 @@ type RegistryResolver struct {
}
func NewRegistryAttestationResolver(image string, platform string) (*RegistryResolver, error) {
p, err := parsePlatform(platform)
p, err := ParsePlatform(platform)
if err != nil {
return nil, err
}

View File

@@ -10,7 +10,7 @@ import (
)
func TestRefToPurl(t *testing.T) {
arm, err := parsePlatform("arm64/linux")
arm, err := ParsePlatform("arm64/linux")
require.NoError(t, err)
purl, canonical, err := RefToPURL("alpine", arm)
assert.NoError(t, err)
@@ -73,13 +73,13 @@ func TestImageDigestForPlatform(t *testing.T) {
mfs2, err := mfs.IndexManifest()
assert.NoError(t, err)
p, err := parsePlatform("linux/amd64")
p, err := ParsePlatform("linux/amd64")
assert.NoError(t, err)
digest, err := imageDigestForPlatform(mfs2, p)
assert.NoError(t, err)
assert.Equal(t, "sha256:da8b190665956ea07890a0273e2a9c96bfe291662f08e2860e868eef69c34620", digest)
p, err = parsePlatform("linux/arm64")
p, err = ParsePlatform("linux/arm64")
assert.NoError(t, err)
digest, err = imageDigestForPlatform(mfs2, p)
assert.NoError(t, err)

View File

@@ -42,5 +42,5 @@ func (r MockResolver) ImageDigest(ctx context.Context) (string, error) {
}
func (r MockResolver) ImagePlatform() (*v1.Platform, error) {
return parsePlatform("linux/amd64")
return ParsePlatform("linux/amd64")
}