Skip to content

Commit

Permalink
fix: copy prompt skipped was missing (#1484)
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
Co-authored-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
Terry Howe and qweeah committed Aug 22, 2024
1 parent d4eccf4 commit 5792c35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
9 changes: 5 additions & 4 deletions cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand Down
17 changes: 16 additions & 1 deletion cmd/oras/internal/display/status/text_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"os"
"strings"
"sync"
"testing"

ocispec "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 5792c35

Please sign in to comment.