Skip to content

Commit 09cf2a6

Browse files
committed
Extend metadata images test with fieldpaths for Annotations
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
1 parent 5124f9e commit 09cf2a6

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

metadata/images_test.go

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func TestImagesList(t *testing.T) {
4949
Size: 10,
5050
MediaType: "application/vnd.containerd.test",
5151
Digest: digest.FromString(id),
52+
Annotations: map[string]string{
53+
"foo": "bar",
54+
},
5255
},
5356
}
5457

@@ -168,6 +171,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
168171
Target: ocispec.Descriptor{
169172
Size: 10,
170173
MediaType: "application/vnd.oci.blab",
174+
Annotations: map[string]string{
175+
"foo": "bar",
176+
},
171177
},
172178
},
173179
expected: images.Image{
@@ -178,6 +184,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
178184
Target: ocispec.Descriptor{
179185
Size: 10,
180186
MediaType: "application/vnd.oci.blab",
187+
Annotations: map[string]string{
188+
"foo": "bar",
189+
},
181190
},
182191
},
183192
},
@@ -203,6 +212,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
203212
Target: ocispec.Descriptor{
204213
Size: 10,
205214
MediaType: "application/vnd.oci.blab",
215+
Annotations: map[string]string{
216+
"foo": "bar",
217+
},
206218
},
207219
},
208220
expected: images.Image{
@@ -213,6 +225,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
213225
Target: ocispec.Descriptor{
214226
Size: 10,
215227
MediaType: "application/vnd.oci.blab",
228+
Annotations: map[string]string{
229+
"foo": "bar",
230+
},
216231
},
217232
},
218233
},
@@ -227,6 +242,10 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
227242
Target: ocispec.Descriptor{
228243
Size: 20, // ignored
229244
MediaType: "application/vnd.oci.blab+ignored", // make sure other stuff is ignored
245+
Annotations: map[string]string{
246+
"not": "bar",
247+
"new": "boo",
248+
},
230249
},
231250
},
232251
fieldpaths: []string{"labels"},
@@ -238,6 +257,41 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
238257
Target: ocispec.Descriptor{
239258
Size: 10,
240259
MediaType: "application/vnd.oci.blab",
260+
Annotations: map[string]string{
261+
"foo": "bar",
262+
"baz": "boo",
263+
},
264+
},
265+
},
266+
},
267+
{
268+
name: "ReplaceLabelsAnnotationsFieldPath",
269+
original: imageBase(),
270+
input: images.Image{
271+
Labels: map[string]string{
272+
"for": "bar",
273+
"boo": "boo",
274+
},
275+
Target: ocispec.Descriptor{
276+
Size: 20, // ignored
277+
MediaType: "application/vnd.oci.blab+ignored", // make sure other stuff is ignored
278+
Annotations: map[string]string{
279+
"foo": "boo",
280+
},
281+
},
282+
},
283+
fieldpaths: []string{"annotations", "labels"},
284+
expected: images.Image{
285+
Labels: map[string]string{
286+
"for": "bar",
287+
"boo": "boo",
288+
},
289+
Target: ocispec.Descriptor{
290+
Size: 10,
291+
MediaType: "application/vnd.oci.blab",
292+
Annotations: map[string]string{
293+
"foo": "boo",
294+
},
241295
},
242296
},
243297
},
@@ -252,6 +306,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
252306
Target: ocispec.Descriptor{
253307
Size: 20, // ignored
254308
MediaType: "application/vnd.oci.blab+ignored", // make sure other stuff is ignored
309+
Annotations: map[string]string{
310+
"foo": "bar",
311+
},
255312
},
256313
},
257314
fieldpaths: []string{"labels.foo"},
@@ -263,6 +320,43 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
263320
Target: ocispec.Descriptor{
264321
Size: 10,
265322
MediaType: "application/vnd.oci.blab",
323+
Annotations: map[string]string{
324+
"foo": "bar",
325+
"baz": "boo",
326+
},
327+
},
328+
},
329+
},
330+
{
331+
name: "ReplaceAnnotation",
332+
original: imageBase(),
333+
input: images.Image{
334+
Labels: map[string]string{
335+
"foo": "baz",
336+
"baz": "bunk",
337+
},
338+
Target: ocispec.Descriptor{
339+
Size: 20, // ignored
340+
MediaType: "application/vnd.oci.blab+ignored", // make sure other stuff is ignored
341+
Annotations: map[string]string{
342+
"foo": "baz",
343+
"baz": "bunk",
344+
},
345+
},
346+
},
347+
fieldpaths: []string{"annotations.foo"},
348+
expected: images.Image{
349+
Labels: map[string]string{
350+
"foo": "bar",
351+
"baz": "boo",
352+
},
353+
Target: ocispec.Descriptor{
354+
Size: 10,
355+
MediaType: "application/vnd.oci.blab",
356+
Annotations: map[string]string{
357+
"foo": "baz",
358+
"baz": "boo",
359+
},
266360
},
267361
},
268362
},
@@ -273,6 +367,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
273367
Target: ocispec.Descriptor{
274368
Size: 10,
275369
MediaType: "application/vnd.oci.blab+replaced",
370+
Annotations: map[string]string{
371+
"fox": "dog",
372+
},
276373
},
277374
},
278375
fieldpaths: []string{"target"},
@@ -284,6 +381,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
284381
Target: ocispec.Descriptor{
285382
Size: 10,
286383
MediaType: "application/vnd.oci.blab+replaced",
384+
Annotations: map[string]string{
385+
"fox": "dog",
386+
},
287387
},
288388
},
289389
},
@@ -298,6 +398,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
298398
Target: ocispec.Descriptor{
299399
Size: 0,
300400
MediaType: "application/vnd.oci.blab",
401+
Annotations: map[string]string{
402+
"foo": "bar",
403+
},
301404
},
302405
},
303406
cause: errdefs.ErrInvalidArgument,
@@ -311,6 +414,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
311414
},
312415
Target: ocispec.Descriptor{
313416
MediaType: "application/vnd.oci.blab",
417+
Annotations: map[string]string{
418+
"foo": "bar",
419+
},
314420
},
315421
},
316422
createerr: errdefs.ErrInvalidArgument,
@@ -352,6 +458,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
352458
Target: ocispec.Descriptor{
353459
Size: 10,
354460
MediaType: "application/vnd.oci.blab",
461+
Annotations: map[string]string{
462+
"foo": "bar",
463+
},
355464
},
356465
},
357466
input: images.Image{
@@ -363,6 +472,9 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
363472
Target: ocispec.Descriptor{
364473
Size: 10,
365474
MediaType: "application/vnd.oci.blab",
475+
Annotations: map[string]string{
476+
"foo": "bar",
477+
},
366478
},
367479
},
368480
cause: errdefs.ErrNotFound,
@@ -440,6 +552,10 @@ func imageBase() images.Image {
440552
Target: ocispec.Descriptor{
441553
Size: 10,
442554
MediaType: "application/vnd.oci.blab",
555+
Annotations: map[string]string{
556+
"foo": "bar",
557+
"baz": "boo",
558+
},
443559
},
444560
}
445561
}

0 commit comments

Comments
 (0)