Skip to content

Commit 2aa6da6

Browse files
committed
add unit test
Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
1 parent a21add3 commit 2aa6da6

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

registry/remote/referrers_test.go

+94
Original file line numberDiff line numberDiff line change
@@ -494,3 +494,97 @@ func Test_applyReferrerChanges(t *testing.T) {
494494
})
495495
}
496496
}
497+
498+
func Test_removeEmptyDescriptors(t *testing.T) {
499+
descs := []ocispec.Descriptor{
500+
{
501+
MediaType: ocispec.MediaTypeDescriptor,
502+
Digest: "sha256:2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae",
503+
Size: 3,
504+
ArtifactType: "foo",
505+
Annotations: map[string]string{"name": "foo"},
506+
},
507+
{
508+
MediaType: ocispec.MediaTypeDescriptor,
509+
Digest: "sha256:fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9",
510+
Size: 3,
511+
ArtifactType: "bar",
512+
Annotations: map[string]string{"name": "bar"},
513+
},
514+
{
515+
MediaType: ocispec.MediaTypeDescriptor,
516+
Digest: "sha256:baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096",
517+
Size: 3,
518+
ArtifactType: "baz",
519+
Annotations: map[string]string{"name": "baz"},
520+
},
521+
}
522+
tests := []struct {
523+
name string
524+
descs []ocispec.Descriptor
525+
hint int
526+
want []ocispec.Descriptor
527+
}{
528+
{
529+
name: "empty list",
530+
descs: []ocispec.Descriptor{},
531+
hint: 0,
532+
want: []ocispec.Descriptor{},
533+
},
534+
{
535+
name: "all non-empty",
536+
descs: descs,
537+
hint: len(descs),
538+
want: descs,
539+
},
540+
{
541+
name: "all empty",
542+
descs: []ocispec.Descriptor{
543+
{},
544+
{},
545+
{},
546+
},
547+
hint: 0,
548+
want: []ocispec.Descriptor{},
549+
},
550+
{
551+
name: "empty rear",
552+
descs: []ocispec.Descriptor{
553+
descs[0],
554+
{},
555+
descs[2],
556+
{},
557+
{},
558+
},
559+
hint: 2,
560+
want: []ocispec.Descriptor{
561+
descs[0],
562+
descs[2],
563+
},
564+
},
565+
{
566+
name: "empty head",
567+
descs: []ocispec.Descriptor{
568+
{},
569+
descs[0],
570+
descs[1],
571+
{},
572+
{},
573+
descs[2],
574+
},
575+
hint: 3,
576+
want: []ocispec.Descriptor{
577+
descs[0],
578+
descs[1],
579+
descs[2],
580+
},
581+
},
582+
}
583+
for _, tt := range tests {
584+
t.Run(tt.name, func(t *testing.T) {
585+
if got := removeEmptyDescriptors(tt.descs, tt.hint); !reflect.DeepEqual(got, tt.want) {
586+
t.Errorf("removeEmptyDescriptors() = %v, want %v", got, tt.want)
587+
}
588+
})
589+
}
590+
}

0 commit comments

Comments
 (0)