Skip to content

Commit 1d6c168

Browse files
committed
Conformance: test for annotation pull up
Signed-off-by: Brandon Mitchell <git@bmitch.net>
1 parent 1af3bd8 commit 1d6c168

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

conformance/03_discovery_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ var test03ContentDiscovery = func() {
316316
Expect(err).To(BeNil())
317317
Expect(len(index.Manifests)).To(Equal(5))
318318
Expect(index.Manifests[0].Digest).ToNot(Equal(index.Manifests[1].Digest))
319+
for i := 0; i < len(index.Manifests); i++ {
320+
Expect(len(index.Manifests[i].Annotations)).To(Equal(1))
321+
Expect(index.Manifests[i].Annotations[testAnnotationKey]).To(Equal(testAnnotationValues[index.Manifests[i].Digest.String()]))
322+
}
319323
})
320324

321325
g.Specify("GET request to existing blob with filter should yield 200", func() {
@@ -339,8 +343,16 @@ var test03ContentDiscovery = func() {
339343
if resp.Header().Get("OCI-Filters-Applied") != "" {
340344
Expect(len(index.Manifests)).To(Equal(2))
341345
Expect(resp.Header().Get("OCI-Filters-Applied")).To(Equal(artifactTypeFilter))
346+
for i := 0; i < len(index.Manifests); i++ {
347+
Expect(len(index.Manifests[i].Annotations)).To(Equal(1))
348+
Expect(index.Manifests[i].Annotations[testAnnotationKey]).To(Equal(testAnnotationValues[index.Manifests[i].Digest.String()]))
349+
}
342350
} else {
343351
Expect(len(index.Manifests)).To(Equal(5))
352+
for i := 0; i < len(index.Manifests); i++ {
353+
Expect(len(index.Manifests[i].Annotations)).To(Equal(1))
354+
Expect(index.Manifests[i].Annotations[testAnnotationKey]).To(Equal(testAnnotationValues[index.Manifests[i].Digest.String()]))
355+
}
344356
Warn("filtering by artifact-type is not implemented")
345357
}
346358
})

conformance/image.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,51 @@ type descriptor struct {
4747
// Size specifies the size in bytes of the blob.
4848
Size int64 `json:"size"`
4949

50+
// URLs specifies a list of URLs from which this object MAY be downloaded
51+
URLs []string `json:"urls,omitempty"`
52+
53+
// Annotations contains arbitrary metadata relating to the targeted content.
54+
Annotations map[string]string `json:"annotations,omitempty"`
55+
5056
// Data specifies the data of the object described by the descriptor.
5157
Data []byte `json:"data,omitempty"`
5258

59+
// Platform describes the platform which the image in the manifest runs on.
60+
//
61+
// This should only be used when referring to a manifest.
62+
Platform *platform `json:"platform,omitempty"`
63+
64+
// ArtifactType is the IANA media type of this artifact.
65+
ArtifactType string `json:"artifactType,omitempty"`
66+
5367
// NewUnspecifiedField is not covered by image-spec.
5468
// Registry implementations should still successfully store and serve
5569
// manifests containing this data.
5670
NewUnspecifiedField []byte `json:"newUnspecifiedField"`
5771
}
5872

73+
// platform describes the platform which the image in the manifest runs on.
74+
type platform struct {
75+
// Architecture field specifies the CPU architecture, for example
76+
// `amd64` or `ppc64le`.
77+
Architecture string `json:"architecture"`
78+
79+
// OS specifies the operating system, for example `linux` or `windows`.
80+
OS string `json:"os"`
81+
82+
// OSVersion is an optional field specifying the operating system
83+
// version, for example on Windows `10.0.14393.1066`.
84+
OSVersion string `json:"os.version,omitempty"`
85+
86+
// OSFeatures is an optional field specifying an array of strings,
87+
// each listing a required OS feature (for example on Windows `win32k`).
88+
OSFeatures []string `json:"os.features,omitempty"`
89+
90+
// Variant is an optional field specifying a variant of the CPU, for
91+
// example `v7` to specify ARMv7 when architecture is `arm`.
92+
Variant string `json:"variant,omitempty"`
93+
}
94+
5995
// rootFS describes a layer content addresses
6096
type rootFS struct {
6197
// Type is the type of the rootfs.

conformance/setup.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ var (
126126
testBlobBChunk2Length string
127127
testBlobBChunk1Range string
128128
testBlobBChunk2Range string
129+
testAnnotationKey string
130+
testAnnotationValues map[string]string
129131
client *reggie.Client
130132
crossmountNamespace string
131133
dummyDigest string
@@ -336,6 +338,9 @@ func init() {
336338

337339
testRefArtifactTypeB = "application/vnd.nba.strawberry.jam.croissant"
338340

341+
testAnnotationKey = "org.opencontainers.conformance.test"
342+
testAnnotationValues = map[string]string{}
343+
339344
// artifact with Subject ref using config.MediaType = artifactType
340345
refsManifestAConfigArtifact := manifest{
341346
SchemaVersion: 2,
@@ -353,6 +358,9 @@ func init() {
353358
Layers: []descriptor{
354359
emptyJSONDescriptor,
355360
},
361+
Annotations: map[string]string{
362+
testAnnotationKey: "test config a",
363+
},
356364
}
357365

358366
refsManifestAConfigArtifactContent, err = json.MarshalIndent(&refsManifestAConfigArtifact, "", "\t")
@@ -361,6 +369,7 @@ func init() {
361369
}
362370

363371
refsManifestAConfigArtifactDigest = godigest.FromBytes(refsManifestAConfigArtifactContent).String()
372+
testAnnotationValues[refsManifestAConfigArtifactDigest] = refsManifestAConfigArtifact.Annotations[testAnnotationKey]
364373

365374
refsManifestBConfigArtifact := manifest{
366375
SchemaVersion: 2,
@@ -378,6 +387,9 @@ func init() {
378387
Layers: []descriptor{
379388
emptyJSONDescriptor,
380389
},
390+
Annotations: map[string]string{
391+
testAnnotationKey: "test config b",
392+
},
381393
}
382394

383395
refsManifestBConfigArtifactContent, err = json.MarshalIndent(&refsManifestBConfigArtifact, "", "\t")
@@ -386,6 +398,7 @@ func init() {
386398
}
387399

388400
refsManifestBConfigArtifactDigest = godigest.FromBytes(refsManifestBConfigArtifactContent).String()
401+
testAnnotationValues[refsManifestBConfigArtifactDigest] = refsManifestBConfigArtifact.Annotations[testAnnotationKey]
389402

390403
// artifact with Subject ref using ArtifactType, config.MediaType = emptyJSON
391404
refsManifestALayerArtifact := manifest{
@@ -405,6 +418,9 @@ func init() {
405418
Digest: godigest.FromBytes(testRefBlobA),
406419
},
407420
},
421+
Annotations: map[string]string{
422+
testAnnotationKey: "test layer a",
423+
},
408424
}
409425

410426
refsManifestALayerArtifactContent, err = json.MarshalIndent(&refsManifestALayerArtifact, "", "\t")
@@ -413,6 +429,7 @@ func init() {
413429
}
414430

415431
refsManifestALayerArtifactDigest = godigest.FromBytes(refsManifestALayerArtifactContent).String()
432+
testAnnotationValues[refsManifestALayerArtifactDigest] = refsManifestALayerArtifact.Annotations[testAnnotationKey]
416433

417434
refsManifestBLayerArtifact := manifest{
418435
SchemaVersion: 2,
@@ -431,6 +448,9 @@ func init() {
431448
Digest: godigest.FromBytes(testRefBlobB),
432449
},
433450
},
451+
Annotations: map[string]string{
452+
testAnnotationKey: "test layer b",
453+
},
434454
}
435455

436456
refsManifestBLayerArtifactContent, err = json.MarshalIndent(&refsManifestBLayerArtifact, "", "\t")
@@ -439,6 +459,7 @@ func init() {
439459
}
440460

441461
refsManifestBLayerArtifactDigest = godigest.FromBytes(refsManifestBLayerArtifactContent).String()
462+
testAnnotationValues[refsManifestBLayerArtifactDigest] = refsManifestBLayerArtifact.Annotations[testAnnotationKey]
442463

443464
testRefArtifactTypeIndex = "application/vnd.food.stand"
444465
refsIndexArtifact := index{
@@ -462,12 +483,16 @@ func init() {
462483
Size: int64(len(manifests[4].Content)),
463484
Digest: godigest.FromBytes(manifests[4].Content),
464485
},
486+
Annotations: map[string]string{
487+
testAnnotationKey: "test index",
488+
},
465489
}
466490
refsIndexArtifactContent, err = json.MarshalIndent(&refsIndexArtifact, "", "\t")
467491
if err != nil {
468492
log.Fatal(err)
469493
}
470494
refsIndexArtifactDigest = godigest.FromBytes(refsIndexArtifactContent).String()
495+
testAnnotationValues[refsIndexArtifactDigest] = refsIndexArtifact.Annotations[testAnnotationKey]
471496

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

0 commit comments

Comments
 (0)