Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix version info for OCI refs #1078

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion api/oci/ociutils/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func ParseVersion(vers string) (*ArtVersion, error) {
Digest: &dig,
}, nil
}
if vers == "" {
return &ArtVersion{}, nil
}
return &ArtVersion{
Tag: &vers,
}, nil
Expand All @@ -50,7 +53,7 @@ type ArtVersion struct {
}

func (v *ArtVersion) VersionSpec() string {
if v != nil {
if v == nil {
return ""
}

Expand Down Expand Up @@ -94,3 +97,20 @@ func (v *ArtVersion) GetTag() string {
}
return ""
}

func (v *ArtVersion) GetDigest() digest.Digest {
if v != nil && v.Digest != nil {
return *v.Digest
}
return ""
}

func (r *ArtVersion) Version() string {
if r.Digest != nil {
return "@" + string(*r.Digest)
}
if r.Tag != nil {
return *r.Tag
}
return "latest"
}
31 changes: 31 additions & 0 deletions api/oci/ociutils/ref_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ociutils_test

import (
. "github.com/mandelsoft/goutils/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/opencontainers/go-digest"
"ocm.software/ocm/api/oci/ociutils"
"ocm.software/ocm/api/oci/testhelper"
)

var _ = Describe("Ref Test Environment", func() {
dig := "sha256:" + testhelper.H_OCIARCHMANIFEST1
DescribeTable("parsing", func(src, yaml, vspec string, isvers bool, vers string, istag bool, tag string, isdig bool, dig string) {
v := Must(ociutils.ParseVersion(src))
Expect(v).NotTo(BeNil())
Expect(v).To(YAMLEqual(yaml))
Expect(v.VersionSpec()).To(Equal(vspec))
Expect(v.IsVersion()).To(Equal(isvers))
Expect(v.Version()).To(Equal(vers))
Expect(v.IsTagged()).To(Equal(istag))
Expect(v.GetTag()).To(Equal(tag))
Expect(v.IsDigested()).To(Equal(isdig))
Expect(v.GetDigest()).To(Equal(digest.Digest(dig)))
},
Entry("empty", "", "{}", "latest", false, "latest", false, "", false, ""),
Entry("tag", "tag", "{\"tag\":\"tag\"}", "tag", true, "tag", true, "tag", false, ""),
Entry("digest", "@"+dig, "{\"digest\":\""+dig+"\"}", "@"+dig, true, "@"+dig, false, "", true, dig),
Entry("tag@digest", "tag@"+dig, "{\"tag\":\"tag\",\"digest\":\""+dig+"\"}", "tag@"+dig, true, "@"+dig, true, "tag", true, dig),
)
})
mandelsoft marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions api/oci/ociutils/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ociutils_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestConfig(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "OCI Utils Test Suite")
}
10 changes: 0 additions & 10 deletions api/oci/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,6 @@ type ArtSpec struct {
ArtVersion `json:",inline"`
}

func (r *ArtSpec) Version() string {
if r.Digest != nil {
return "@" + string(*r.Digest)
}
if r.Tag != nil {
return *r.Tag
}
return "latest"
}

func (r *ArtSpec) IsRegistry() bool {
return r.Repository == ""
}
Expand Down
8 changes: 4 additions & 4 deletions api/oci/testhelper/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func OCIArtifactResource1(env *builder.Builder, name string, host string, funcs

const (
D_OCIMANIFEST1 = "0c4abdb72cf59cb4b77f4aacb4775f9f546ebc3face189b2224a966c8826ca9f"
H_OCIARCHMANIFEST1 = "818fb6a69a5f55e8b3dbc921a61fdd000b9445a745b587ba753a811b02426326"
// H_OCIARCHMANIFEST1 = "b0692bcec00e0a875b6b280f3209d6776f3eca128adcb7e81e82fd32127c0c62".
H_OCIARCHMANIFEST1 = "b0692bcec00e0a875b6b280f3209d6776f3eca128adcb7e81e82fd32127c0c62"
// H_OCIARCHMANIFEST1 = "818fb6a69a5f55e8b3dbc921a61fdd000b9445a745b587ba753a811b02426326".
)

var DS_OCIMANIFEST1 = &metav1.DigestSpec{
Expand Down Expand Up @@ -124,8 +124,8 @@ func OCIManifest2For(env *builder.Builder, ns, tag string, nested ...func()) (*a

const (
D_OCIMANIFEST2 = "c2d2dca275c33c1270dea6168a002d67c0e98780d7a54960758139ae19984bd7"
H_OCIARCHMANIFEST2 = "2aaf6f8857dcbfa04a72fb98dd53f649b46e5d81aa4fb17330df74b0ffc30839"
// H_OCIARCHMANIFEST2 = "cb85cd58b10e36343971691abbfe40200cb645c6e95f0bdabd111a30cf794708".
H_OCIARCHMANIFEST2 = "cb85cd58b10e36343971691abbfe40200cb645c6e95f0bdabd111a30cf794708"
// H_OCIARCHMANIFEST2 = "2aaf6f8857dcbfa04a72fb98dd53f649b46e5d81aa4fb17330df74b0ffc30839".
)

func HashManifest2(fmt string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Method", func() {
return m.Close()
})
data := Must(m.Get())
Expect(len(data)).To(Equal(630))
Expect(len(data)).To(Equal(628))
Expect(accspeccpi.GetAccessMethodImplementation(m).(blobaccess.DigestSource).Digest().String()).To(Equal("sha256:0c4abdb72cf59cb4b77f4aacb4775f9f546ebc3face189b2224a966c8826ca9f"))
Expect(utils.GetOCIArtifactRef(env, res)).To(Equal("ocm/value:v2.0"))
})
Expand Down