Skip to content

Commit

Permalink
Add index with subject conformance test (#436)
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Mitchell <[email protected]>
Co-authored-by: Josh Dolitsky <[email protected]>
  • Loading branch information
sudo-bmitch and jdolitsky authored Jul 25, 2023
1 parent b1e549b commit e7db307
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
22 changes: 20 additions & 2 deletions conformance/03_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ var test03ContentDiscovery = func() {
BeNumerically("<", 300)))
Expect(resp.Header().Get("OCI-Subject")).To(Equal(manifests[4].Digest))

// Populate registry with test index manifest
req = client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsIndexArtifactDigest)).
SetHeader("Content-Type", "application/vnd.oci.image.index.v1+json").
SetBody(refsIndexArtifactContent)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
Expect(resp.Header().Get("OCI-Subject")).To(Equal(manifests[4].Digest))

// Populate registry with test blob
req = client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/")
resp, err = client.Do(req)
Expand Down Expand Up @@ -300,7 +312,7 @@ var test03ContentDiscovery = func() {
var index index
err = json.Unmarshal(resp.Body(), &index)
Expect(err).To(BeNil())
Expect(len(index.Manifests)).To(Equal(4))
Expect(len(index.Manifests)).To(Equal(5))
Expect(index.Manifests[0].Digest).ToNot(Equal(index.Manifests[1].Digest))
})

Expand All @@ -325,7 +337,7 @@ var test03ContentDiscovery = func() {
Expect(len(index.Manifests)).To(Equal(2))
Expect(resp.Header().Get("OCI-Filters-Applied")).To(Equal(artifactTypeFilter))
} else {
Expect(len(index.Manifests)).To(Equal(4))
Expect(len(index.Manifests)).To(Equal(5))
Warn("filtering by artifact-type is not implemented")
}
})
Expand Down Expand Up @@ -414,6 +426,9 @@ var test03ContentDiscovery = func() {

if deleteManifestBeforeBlobs {
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsIndexArtifactDigest))
deleteReq(req)
req = client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsManifestAConfigArtifactDigest))
deleteReq(req)
req = client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
Expand Down Expand Up @@ -445,6 +460,9 @@ var test03ContentDiscovery = func() {

if !deleteManifestBeforeBlobs {
// Delete manifest created in setup
req = client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsIndexArtifactDigest))
deleteReq(req)
req = client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsManifestAConfigArtifactDigest))
deleteReq(req)
Expand Down
9 changes: 9 additions & 0 deletions conformance/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type manifest struct {

// Subject is an optional link from the image manifest to another manifest forming an association between the image manifest and the other manifest.
Subject *descriptor `json:"subject,omitempty"`

// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}

// descriptor describes the disposition of targeted content.
Expand Down Expand Up @@ -90,9 +93,15 @@ type index struct {
// MediaType specifies the type of this document data structure e.g. `application/vnd.oci.image.index.v1+json`
MediaType string `json:"mediaType,omitempty"`

// ArtifactType specifies the IANA media type of artifact when the manifest is used for an artifact.
ArtifactType string `json:"artifactType,omitempty"`

// Manifests references platform specific manifests.
Manifests []descriptor `json:"manifests"`

// Subject is an optional link from the image manifest to another manifest forming an association between the image manifest and the other manifest.
Subject *descriptor `json:"subject,omitempty"`

// Annotations contains arbitrary metadata for the image index.
Annotations map[string]string `json:"annotations,omitempty"`
}
32 changes: 32 additions & 0 deletions conformance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ var (
testRefBlobADigest string
testRefArtifactTypeA string
testRefArtifactTypeB string
testRefArtifactTypeIndex string
testRefBlobB []byte
testRefBlobBLength string
testRefBlobBDigest string
Expand Down Expand Up @@ -144,6 +145,8 @@ var (
refsManifestBConfigArtifactDigest string
refsManifestBLayerArtifactContent []byte
refsManifestBLayerArtifactDigest string
refsIndexArtifactContent []byte
refsIndexArtifactDigest string
reportJUnitFilename string
reportHTMLFilename string
httpWriter *httpDebugWriter
Expand Down Expand Up @@ -435,6 +438,35 @@ func init() {

refsManifestBLayerArtifactDigest = godigest.FromBytes(refsManifestBLayerArtifactContent).String()

testRefArtifactTypeIndex = "application/vnd.food.stand"
refsIndexArtifact := index{
SchemaVersion: 2,
MediaType: "application/vnd.oci.image.index.v1+json",
ArtifactType: testRefArtifactTypeIndex,
Manifests: []descriptor{
{
MediaType: "application/vnd.oci.image.manifest.v1+json",
Size: int64(len(refsManifestAConfigArtifactContent)),
Digest: godigest.FromBytes(refsManifestAConfigArtifactContent),
},
{
MediaType: "application/vnd.oci.image.manifest.v1+json",
Size: int64(len(refsManifestALayerArtifactContent)),
Digest: godigest.FromBytes(refsManifestALayerArtifactContent),
},
},
Subject: &descriptor{
MediaType: "application/vnd.oci.image.manifest.v1+json",
Size: int64(len(manifests[4].Content)),
Digest: godigest.FromBytes(manifests[4].Content),
},
}
refsIndexArtifactContent, err = json.MarshalIndent(&refsIndexArtifact, "", "\t")
if err != nil {
log.Fatal(err)
}
refsIndexArtifactDigest = godigest.FromBytes(refsIndexArtifactContent).String()

dummyDigest = godigest.FromString("hello world").String()

errorCodes = []string{
Expand Down

0 comments on commit e7db307

Please sign in to comment.