From f8b293e665915f467b08297cccede2f3bcf9e521 Mon Sep 17 00:00:00 2001 From: richardoriginal Date: Thu, 13 Feb 2025 14:59:50 +0000 Subject: [PATCH] crane package options modified exposing WithPageSize, adding pageSize option, and including a test for the function --- pkg/crane/options.go | 12 ++++++++++++ pkg/crane/options_test.go | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/crane/options.go b/pkg/crane/options.go index d9d441761..36d20ef88 100644 --- a/pkg/crane/options.go +++ b/pkg/crane/options.go @@ -38,6 +38,8 @@ type Options struct { jobs int noclobber bool ctx context.Context + // pageSize for paginations + pageSize int } // GetOptions exposes the underlying []remote.Option, []name.Option, and @@ -176,3 +178,13 @@ func WithNoClobber(noclobber bool) Option { o.noclobber = noclobber } } + +// WithPageSize sets the given size as the value of parameter 'n' in the request. +// +// To omit the `n` parameter entirely, use WithPageSize(0). +// The default value is 1000. +func WithPageSize(size int) Option { + return func(o *Options) { + o.pageSize = size + } +} diff --git a/pkg/crane/options_test.go b/pkg/crane/options_test.go index eaee3cf24..7683a2be9 100644 --- a/pkg/crane/options_test.go +++ b/pkg/crane/options_test.go @@ -56,3 +56,12 @@ func TestInsecureTransport(t *testing.T) { t.Errorf("got: %t\nwant: %t", got, want) } } + +func TestWithPageSize(t *testing.T) { + want := 1000 // default pageSize + opts := GetOptions(WithPageSize(want)) + + if got := opts.pageSize; got != want { + t.Errorf("got %d\nwant: %d", got, want) + } +}