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

WithProgress option for crane push/pull #1868

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/crane/options.go
Expand Up @@ -109,6 +109,17 @@ func WithPlatform(platform *v1.Platform) Option {
}
}

// WithProgress is an option which takes a channel that will receive
// progress updates as bytes are written.
//
// Sending updates to an unbuffered channel will block writes, so callers
// should provide a buffered channel to avoid potential deadlocks.
func WithProgress(updates chan<- v1.Update) Option {
return func(o *Options) {
o.Remote = append(o.Remote, remote.WithProgress(updates))
}
}

// WithAuthFromKeychain is a functional option for overriding the default
// authenticator for remote operations, using an authn.Keychain to find
// credentials.
Expand Down
11 changes: 11 additions & 0 deletions pkg/crane/options_test.go
Expand Up @@ -19,6 +19,7 @@ import (
"net/http"
"testing"

v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
)

Expand Down Expand Up @@ -56,3 +57,13 @@ func TestInsecureTransport(t *testing.T) {
t.Errorf("got: %t\nwant: %t", got, want)
}
}

func TestWithProgress(t *testing.T) {
c := make(chan v1.Update, 100)

opts := GetOptions(WithProgress(c))

if len(opts.Remote) != 2 {
t.Errorf("expected 1 remote option, got %d", len(opts.Remote))
}
}