Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: copy prompt skipped was missing #1484

Merged
merged 3 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
qweeah marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Loading