From 5792c35622a75a87d8f7e29f0a8b4e33105a13df Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Thu, 22 Aug 2024 04:41:39 -0600 Subject: [PATCH] fix: copy prompt skipped was missing (#1484) Signed-off-by: Terry Howe Signed-off-by: Billy Zha Co-authored-by: Billy Zha --- cmd/oras/internal/display/status/text.go | 9 +++++---- cmd/oras/internal/display/status/text_test.go | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 2ac3a6235..c4277199f 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -17,9 +17,10 @@ package status import ( "context" - "oras.land/oras/internal/graph" "sync" + "oras.land/oras/internal/graph" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2" "oras.land/oras-go/v2/content" @@ -161,12 +162,12 @@ func (ch *TextCopyHandler) PreCopy(_ context.Context, desc ocispec.Descriptor) e // PostCopy implements PostCopy of CopyHandler. func (ch *TextCopyHandler) PostCopy(ctx context.Context, desc ocispec.Descriptor) error { ch.committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) - successors, err := graph.FilteredSuccessors(ctx, desc, ch.fetcher, DeduplicatedFilter(ch.committed)) + deduplicated, err := graph.FilteredSuccessors(ctx, desc, ch.fetcher, DeduplicatedFilter(ch.committed)) if err != nil { return err } - for _, successor := range successors { - if err = ch.printer.PrintStatus(successor, copyPromptExists); err != nil { + for _, successor := range deduplicated { + if err = ch.printer.PrintStatus(successor, copyPromptSkipped); err != nil { return err } } diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index 6a1d7c75d..8e68aa76b 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -19,6 +19,7 @@ import ( "context" "os" "strings" + "sync" "testing" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -68,7 +69,7 @@ func TestTextCopyHandler_OnCopySkipped(t *testing.T) { validatePrinted(t, "Exists 0b442c23c1dd oci-image") } -func TestTextCopyHandler_PostCopy(t *testing.T) { +func TestTextCopyHandler_PostCopy_titled(t *testing.T) { builder.Reset() ch := NewTextCopyHandler(printer, mockFetcher.Fetcher) if ch.PostCopy(ctx, mockFetcher.OciImage) != nil { @@ -80,6 +81,20 @@ func TestTextCopyHandler_PostCopy(t *testing.T) { validatePrinted(t, "Copied 0b442c23c1dd oci-image") } +func TestTextCopyHandler_PostCopy_skipped(t *testing.T) { + builder.Reset() + ch := &TextCopyHandler{ + printer: printer, + fetcher: mockFetcher.Fetcher, + committed: &sync.Map{}, + } + ch.committed.Store(mockFetcher.ImageLayer.Digest.String(), mockFetcher.ImageLayer.Annotations[ocispec.AnnotationTitle]+"bogus") + if err := ch.PostCopy(ctx, mockFetcher.OciImage); err != nil { + t.Error("PostCopy() returns unexpected err:", err) + } + validatePrinted(t, "Skipped f6b87e8e0fe1 layer\nCopied 0b442c23c1dd oci-image") +} + func TestTextCopyHandler_PreCopy(t *testing.T) { builder.Reset() ch := NewTextCopyHandler(printer, mockFetcher.Fetcher)