Skip to content

Commit 82344fc

Browse files
author
Xiaoxuan Wang
committed
added tests
Signed-off-by: Xiaoxuan Wang <[email protected]>
1 parent f26e428 commit 82344fc

File tree

1 file changed

+134
-14
lines changed

1 file changed

+134
-14
lines changed

test/e2e/suite/command/discover.go

+134-14
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,27 @@ var _ = Describe("1.1 registry users:", func() {
278278
})
279279

280280
var _ = Describe("1.0 registry users:", func() {
281+
type referrer struct {
282+
ocispec.Descriptor
283+
Manifests []ocispec.Descriptor
284+
}
285+
type subject struct {
286+
ocispec.Descriptor
287+
Manifests []referrer
288+
}
281289
subjectRef := RegistryRef(FallbackHost, ArtifactRepo, foobar.Tag)
282290
When("running discover command", func() {
283-
It("should discover direct referrers of a subject via json output", func() {
284-
bytes := ORAS("discover", subjectRef, "-o", "json").Exec().Out.Contents()
285-
var index ocispec.Index
286-
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
287-
Expect(index.Manifests).To(HaveLen(1))
288-
Expect(index.Manifests).Should(ContainElement(foobar.SBOMImageReferrer))
291+
It("should discover all direct and indirect referrers of a subject by default via json output", func() {
292+
bytes := ORAS("discover", subjectRef, "--format", "json").Exec().Out.Contents()
293+
var subject subject
294+
// should show direct referrers correctly
295+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
296+
Expect(subject.Manifests).To(HaveLen(1))
297+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
298+
// should show indirect referrers correctly
299+
referrer := subject.Manifests[0]
300+
Expect(referrer.Manifests).To(HaveLen(1))
301+
Expect(referrer.Manifests[0]).Should(Equal(foobar.SignatureImageReferrer))
289302
})
290303

291304
It("should discover matched referrer when filtering via json output", func() {
@@ -303,13 +316,52 @@ var _ = Describe("1.0 registry users:", func() {
303316
Expect(index.Manifests).To(HaveLen(0))
304317
})
305318

306-
It("should discover all referrers of a subject via tree output", func() {
319+
It("should discover referrers correctly by depth 1 via json output", func() {
320+
bytes := ORAS("discover", subjectRef, "--format", "json", "--depth", "1").Exec().Out.Contents()
321+
var subject subject
322+
// should show direct referrers correctly
323+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
324+
Expect(subject.Manifests).To(HaveLen(1))
325+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
326+
// should not show indirect referrers
327+
referrer := subject.Manifests[0]
328+
Expect(referrer.Manifests).To(HaveLen(0))
329+
})
330+
331+
It("should discover referrers correctly by depth 2", func() {
332+
bytes := ORAS("discover", subjectRef, "--format", "json", "--depth", "2").Exec().Out.Contents()
333+
var subject subject
334+
// should show direct referrers correctly
335+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
336+
Expect(subject.Manifests).To(HaveLen(1))
337+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
338+
// should show indirect referrers correctly
339+
referrer := subject.Manifests[0]
340+
Expect(referrer.Manifests).To(HaveLen(1))
341+
Expect(referrer.Manifests[0]).Should(Equal(foobar.SignatureImageReferrer))
342+
})
343+
344+
It("should discover all direct and indirect referrers of a subject by default via tree output", func() {
307345
referrers := []ocispec.Descriptor{foobar.SBOMImageReferrer, foobar.SignatureImageReferrer}
308346
ORAS("discover", subjectRef, "-o", "tree").
309347
MatchKeyWords(append(discoverKeyWords(false, referrers...), RegistryRef(FallbackHost, ArtifactRepo, foobar.Digest))...).
310348
Exec()
311349
})
312350

351+
It("should discover referrers correctly by depth 1 via tree output", func() {
352+
out := ORAS("discover", subjectRef, "--format", "tree", "--depth", "1").
353+
MatchKeyWords(RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest)).Exec().Out
354+
Expect(out).To(gbytes.Say(foobar.SBOMImageReferrer.Digest.String()))
355+
Expect(out).NotTo(gbytes.Say(foobar.SignatureImageReferrer.Digest.String()))
356+
})
357+
358+
It("should discover referrers correctly by depth 2", func() {
359+
out := ORAS("discover", subjectRef, "--format", "tree", "--depth", "2").
360+
MatchKeyWords(RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest)).Exec().Out
361+
Expect(out).To(gbytes.Say(foobar.SBOMImageReferrer.Digest.String()))
362+
Expect(out).To(gbytes.Say(foobar.SignatureImageReferrer.Digest.String()))
363+
})
364+
313365
It("should discover all referrers with annotation via tree output", func() {
314366
referrers := []ocispec.Descriptor{foobar.SBOMImageReferrer, foobar.SignatureImageReferrer}
315367
ORAS("discover", subjectRef, "-o", "tree", "-v").
@@ -335,17 +387,63 @@ var _ = Describe("1.0 registry users:", func() {
335387

336388
var _ = Describe("OCI image layout users:", func() {
337389
When("running discover command with json output", func() {
390+
type referrer struct {
391+
ocispec.Descriptor
392+
Manifests []ocispec.Descriptor
393+
}
394+
type subject struct {
395+
ocispec.Descriptor
396+
Manifests []referrer
397+
}
338398
format := "json"
339-
It("should discover direct referrers of a subject", func() {
399+
It("should discover direct and indirect referrers of a subject by default", func() {
340400
// prepare
341401
root := PrepareTempOCI(ArtifactRepo)
342402
subjectRef := LayoutRef(root, foobar.Tag)
343403
// test
344-
bytes := ORAS("discover", subjectRef, "-o", format, Flags.Layout).Exec().Out.Contents()
345-
var index ocispec.Index
346-
Expect(json.Unmarshal(bytes, &index)).ShouldNot(HaveOccurred())
347-
Expect(index.Manifests).To(HaveLen(1))
348-
Expect(index.Manifests).Should(ContainElement(foobar.SBOMImageReferrer))
404+
bytes := ORAS("discover", subjectRef, "--format", format, Flags.Layout).Exec().Out.Contents()
405+
var subject subject
406+
// should show direct referrers correctly
407+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
408+
Expect(subject.Manifests).To(HaveLen(1))
409+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
410+
// should show indirect referrers correctly
411+
referrer := subject.Manifests[0]
412+
Expect(referrer.Manifests).To(HaveLen(1))
413+
Expect(referrer.Manifests[0]).Should(Equal(foobar.SignatureImageReferrer))
414+
})
415+
416+
It("should discover referrers correctly by depth 1", func() {
417+
// prepare
418+
root := PrepareTempOCI(ArtifactRepo)
419+
subjectRef := LayoutRef(root, foobar.Tag)
420+
// test
421+
bytes := ORAS("discover", subjectRef, "--format", format, Flags.Layout, "--depth", "1").Exec().Out.Contents()
422+
var subject subject
423+
// should show direct referrers correctly
424+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
425+
Expect(subject.Manifests).To(HaveLen(1))
426+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
427+
// should not show indirect referrers
428+
referrer := subject.Manifests[0]
429+
Expect(referrer.Manifests).To(HaveLen(0))
430+
})
431+
432+
It("should discover referrers correctly by depth 2", func() {
433+
// prepare
434+
root := PrepareTempOCI(ArtifactRepo)
435+
subjectRef := LayoutRef(root, foobar.Tag)
436+
// test
437+
bytes := ORAS("discover", subjectRef, "--format", format, Flags.Layout, "--depth", "2").Exec().Out.Contents()
438+
var subject subject
439+
// should show direct referrers correctly
440+
Expect(json.Unmarshal(bytes, &subject)).ShouldNot(HaveOccurred())
441+
Expect(subject.Manifests).To(HaveLen(1))
442+
Expect(subject.Manifests[0].Descriptor).Should(Equal(foobar.SBOMImageReferrer))
443+
// should show indirect referrers correctly
444+
referrer := subject.Manifests[0]
445+
Expect(referrer.Manifests).To(HaveLen(1))
446+
Expect(referrer.Manifests[0]).Should(Equal(foobar.SignatureImageReferrer))
349447
})
350448

351449
It("should discover matched referrer when filtering", func() {
@@ -380,11 +478,33 @@ var _ = Describe("OCI image layout users:", func() {
380478
root := PrepareTempOCI(ArtifactRepo)
381479
subjectRef := LayoutRef(root, foobar.Tag)
382480
// test
383-
ORAS("discover", subjectRef, "-o", format, Flags.Layout).
481+
ORAS("discover", subjectRef, "--format", format, Flags.Layout).
384482
MatchKeyWords(append(discoverKeyWords(false, referrers...), LayoutRef(root, foobar.Digest))...).
385483
Exec()
386484
})
387485

486+
It("should discover referrers correctly by depth 1", func() {
487+
// prepare
488+
root := PrepareTempOCI(ArtifactRepo)
489+
subjectRef := LayoutRef(root, foobar.Tag)
490+
// test
491+
out := ORAS("discover", subjectRef, "--format", format, Flags.Layout, "--depth", "1").
492+
MatchKeyWords(RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest)).Exec().Out
493+
Expect(out).To(gbytes.Say(foobar.SBOMImageReferrer.Digest.String()))
494+
Expect(out).NotTo(gbytes.Say(foobar.SignatureImageReferrer.Digest.String()))
495+
})
496+
497+
It("should discover referrers correctly by depth 2", func() {
498+
// prepare
499+
root := PrepareTempOCI(ArtifactRepo)
500+
subjectRef := LayoutRef(root, foobar.Tag)
501+
// test
502+
out := ORAS("discover", subjectRef, "--format", format, Flags.Layout, "--depth", "2").
503+
MatchKeyWords(RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest)).Exec().Out
504+
Expect(out).To(gbytes.Say(foobar.SBOMImageReferrer.Digest.String()))
505+
Expect(out).To(gbytes.Say(foobar.SignatureImageReferrer.Digest.String()))
506+
})
507+
388508
It("should discover all referrers of a subject with annotations", func() {
389509
// prepare
390510
root := PrepareTempOCI(ArtifactRepo)

0 commit comments

Comments
 (0)