From 9732d14eb5d12283ff999d58290c909646b2bc00 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang <103478229+wangxiaoxuan273@users.noreply.github.com> Date: Fri, 12 Apr 2024 09:57:08 +0800 Subject: [PATCH] feat: oras discover should show a placeholder of artifactType if it's not presented (#1336) Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/display/metadata/tree/discover.go | 3 +++ test/e2e/suite/command/discover.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/cmd/oras/internal/display/metadata/tree/discover.go b/cmd/oras/internal/display/metadata/tree/discover.go index 64abbb811..496de1279 100644 --- a/cmd/oras/internal/display/metadata/tree/discover.go +++ b/cmd/oras/internal/display/metadata/tree/discover.go @@ -61,6 +61,9 @@ func (h *discoverHandler) OnDiscovered(referrer, subject ocispec.Descriptor) err if !ok { return fmt.Errorf("unexpected subject descriptor: %v", subject) } + if referrer.ArtifactType == "" { + referrer.ArtifactType = "" + } referrerNode := node.AddPath(referrer.ArtifactType, referrer.Digest) if h.verbose { for k, v := range referrer.Annotations { diff --git a/test/e2e/suite/command/discover.go b/test/e2e/suite/command/discover.go index ef320d0b2..58fba9942 100644 --- a/test/e2e/suite/command/discover.go +++ b/test/e2e/suite/command/discover.go @@ -172,6 +172,12 @@ var _ = Describe("1.1 registry users:", func() { MatchKeyWords(append(discoverKeyWords(true, referrers...), RegistryRef(ZOTHost, ArtifactRepo, foobar.Digest))...). Exec() }) + + It("should display if a referrer has an empty artifact type", func() { + ORAS("discover", RegistryRef(ZOTHost, ArtifactRepo, "multi"), "--format", format). + MatchKeyWords(""). + Exec() + }) }) When("running discover command with table output", func() { format := "table"