From 2c7a9feb8d425ff2a0b3f9b53f213eae307e5c98 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Fri, 20 Sep 2019 22:10:31 +0000 Subject: [PATCH 01/10] adds support for the /v2/_catalog API --- pkg/v1/remote/catalog.go | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 pkg/v1/remote/catalog.go diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go new file mode 100644 index 000000000..273cb9762 --- /dev/null +++ b/pkg/v1/remote/catalog.go @@ -0,0 +1,69 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package remote + +import ( + "encoding/json" + "net/http" + "net/url" + + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote/transport" +) + +type catalog struct { + Repos []string `json:"repositories"` +} + +// GetCatalog calls /_catalog, returning the list of repositories on the registry +func GetCatalog(target name.Registry, options ...Option) ([]string, error) { + + o, err := makeOptions(target, options...) + if err != nil { + return nil, err + } + scopes := []string{target.Scope(transport.PullScope)} + tr, err := transport.New(target, o.auth, o.transport, scopes) + if err != nil { + return nil, err + } + + uri := url.URL{ + Scheme: target.Scheme(), + Host: target.RegistryStr(), + Path: "/v2/_catalog", + } + + client := http.Client{Transport: tr} + resp, err := client.Get(uri.String()) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if err := transport.CheckError(resp, http.StatusOK); err != nil { + return nil, err + } + + parsed := catalog{} + if err := json.NewDecoder(resp.Body).Decode(&parsed); err != nil { + return nil, err + } + + //TKTK:JM iterate through results with "last" + return parsed.Repos, nil +} + +//TKTK:JM write tests From c765a4204f4ae8878293ba6015c6df0635896a58 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Fri, 20 Sep 2019 22:37:00 +0000 Subject: [PATCH 02/10] adds pagination to registry catalog function --- pkg/v1/remote/catalog.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 273cb9762..59eb47d26 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -16,6 +16,7 @@ package remote import ( "encoding/json" + "fmt" "net/http" "net/url" @@ -28,7 +29,7 @@ type catalog struct { } // GetCatalog calls /_catalog, returning the list of repositories on the registry -func GetCatalog(target name.Registry, options ...Option) ([]string, error) { +func GetCatalog(target name.Registry, last string, n int, options ...Option) ([]string, error) { o, err := makeOptions(target, options...) if err != nil { @@ -40,10 +41,15 @@ func GetCatalog(target name.Registry, options ...Option) ([]string, error) { return nil, err } + var query string + + query = fmt.Sprintf("last=%s&n=%d", url.QueryEscape(last), n) + uri := url.URL{ - Scheme: target.Scheme(), - Host: target.RegistryStr(), - Path: "/v2/_catalog", + Scheme: target.Scheme(), + Host: target.RegistryStr(), + Path: "/v2/_catalog", + RawQuery: query, } client := http.Client{Transport: tr} From c4425a34817325b2ddc27b558f468a3e475a8f04 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Sat, 21 Sep 2019 00:21:26 +0000 Subject: [PATCH 03/10] Addresses review comments and adds tests for catalog request feature --- pkg/v1/remote/catalog.go | 11 ++--- pkg/v1/remote/catalog_test.go | 84 +++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 pkg/v1/remote/catalog_test.go diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 59eb47d26..57903c8ba 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -30,20 +30,18 @@ type catalog struct { // GetCatalog calls /_catalog, returning the list of repositories on the registry func GetCatalog(target name.Registry, last string, n int, options ...Option) ([]string, error) { - o, err := makeOptions(target, options...) if err != nil { return nil, err } + scopes := []string{target.Scope(transport.PullScope)} tr, err := transport.New(target, o.auth, o.transport, scopes) if err != nil { return nil, err } - var query string - - query = fmt.Sprintf("last=%s&n=%d", url.QueryEscape(last), n) + query := fmt.Sprintf("last=%s&n=%d", url.QueryEscape(last), n) uri := url.URL{ Scheme: target.Scheme(), @@ -63,13 +61,10 @@ func GetCatalog(target name.Registry, last string, n int, options ...Option) ([] return nil, err } - parsed := catalog{} + var parsed catalog if err := json.NewDecoder(resp.Body).Decode(&parsed); err != nil { return nil, err } - //TKTK:JM iterate through results with "last" return parsed.Repos, nil } - -//TKTK:JM write tests diff --git a/pkg/v1/remote/catalog_test.go b/pkg/v1/remote/catalog_test.go new file mode 100644 index 000000000..c5402e054 --- /dev/null +++ b/pkg/v1/remote/catalog_test.go @@ -0,0 +1,84 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package remote + +import ( + "net/http" + "net/http/httptest" + "net/url" + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" +) + +func TestGetCatalog(t *testing.T) { + cases := []struct { + name string + responseBody []byte + wantErr bool + wantRepos []string + }{{ + name: "success", + responseBody: []byte(`{"repositories":["test/test","foo/bar"]}`), + wantErr: false, + wantRepos: []string{"test/test", "foo/bar"}, + }, { + name: "not json", + responseBody: []byte("notjson"), + wantErr: true, + }} + //TODO: add test cases for pagination + + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + catalogPath := "/v2/_catalog" + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case "/v2/": + w.WriteHeader(http.StatusOK) + case catalogPath: + if r.Method != http.MethodGet { + t.Errorf("Method; got %v, want %v", r.Method, http.MethodGet) + } + + w.Write(tc.responseBody) + default: + t.Fatalf("Unexpected path: %v", r.URL.Path) + } + })) + defer server.Close() + u, err := url.Parse(server.URL) + if err != nil { + t.Fatalf("url.Parse(%v) = %v", server.URL, err) + } + + reg, err := name.NewRegistry(u.Host) + if err != nil { + t.Fatalf("name.NewRegistry(%v) = %v", u.Host, err) + } + + repos, err := GetCatalog(reg, "", 100, WithAuthFromKeychain(authn.DefaultKeychain)) + if (err != nil) != tc.wantErr { + t.Errorf("GetCatalog() wrong error: %v, want %v: %v\n", (err != nil), tc.wantErr, err) + } + + if diff := cmp.Diff(tc.wantRepos, repos); diff != "" { + t.Errorf("GetCatalog() wrong repos (-want +got) = %s", diff) + } + }) + } +} From 11dd27827134767e48bf65727653a3bd16b09f38 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Tue, 1 Oct 2019 22:16:57 +0000 Subject: [PATCH 04/10] adds a helper function in crane to retrieve all repos from the remote registry --- cmd/crane/cmd/catalog.go | 45 +++++++++++++++++++++++++++++++++++ pkg/crane/catalog.go | 51 ++++++++++++++++++++++++++++++++++++++++ pkg/v1/remote/catalog.go | 4 ++-- 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 cmd/crane/cmd/catalog.go create mode 100644 pkg/crane/catalog.go diff --git a/cmd/crane/cmd/catalog.go b/cmd/crane/cmd/catalog.go new file mode 100644 index 000000000..754323eff --- /dev/null +++ b/cmd/crane/cmd/catalog.go @@ -0,0 +1,45 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cmd + +import ( + "fmt" + "log" + + "github.com/google/go-containerregistry/pkg/crane" + "github.com/spf13/cobra" +) + +func init() { Root.AddCommand(NewCmdGetCatalog()) } + +// NewCmdGetCatalog creates a new cobra.Command for the repos subcommand. +func NewCmdGetCatalog() *cobra.Command { + return &cobra.Command{ + Use: "repos", + Short: "List the repos in a registry", + Args: cobra.ExactArgs(1), + Run: func(_ *cobra.Command, args []string) { + reg := args[0] + repos, err := crane.GetCatalog(reg) + if err != nil { + log.Fatalf("reading repos for %s: %v", reg, err) + } + + for _, repo := range repos { + fmt.Println(repo) + } + }, + } +} diff --git a/pkg/crane/catalog.go b/pkg/crane/catalog.go new file mode 100644 index 000000000..0399e3dd8 --- /dev/null +++ b/pkg/crane/catalog.go @@ -0,0 +1,51 @@ +// Copyright 2018 Google LLC All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package crane + +import ( + "github.com/google/go-containerregistry/pkg/authn" + "github.com/google/go-containerregistry/pkg/name" + "github.com/google/go-containerregistry/pkg/v1/remote" +) + +// GetCatalog returns the repositories in a registry's catalog +func GetCatalog(src string) (res []string, err error) { + reg, err := name.NewRegistry(src) + if err != nil { + return nil, err + } + + n := 100 + last := "" + for { + + page, err := remote.GetCatalogPage(reg, last, n, remote.WithAuthFromKeychain(authn.DefaultKeychain)) + if err != nil { + return nil, err + } + + if len(page) > 0 { + last = page[len(page)-1] + res = append(res, page...) + } + + if len(page) < n { + break + } + + } + + return res, nil +} diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 57903c8ba..975c548f9 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -28,8 +28,8 @@ type catalog struct { Repos []string `json:"repositories"` } -// GetCatalog calls /_catalog, returning the list of repositories on the registry -func GetCatalog(target name.Registry, last string, n int, options ...Option) ([]string, error) { +// GetCatalogPage calls /_catalog, returning the list of repositories on the registry +func GetCatalogPage(target name.Registry, last string, n int, options ...Option) ([]string, error) { o, err := makeOptions(target, options...) if err != nil { return nil, err From 023e4fd457705068be193f9921c41c922da2d3a6 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Wed, 2 Oct 2019 23:29:05 +0000 Subject: [PATCH 05/10] fixes the testcase name --- pkg/v1/remote/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/v1/remote/catalog_test.go b/pkg/v1/remote/catalog_test.go index c5402e054..771277fad 100644 --- a/pkg/v1/remote/catalog_test.go +++ b/pkg/v1/remote/catalog_test.go @@ -25,7 +25,7 @@ import ( "github.com/google/go-containerregistry/pkg/name" ) -func TestGetCatalog(t *testing.T) { +func TestGetCatalogPage(t *testing.T) { cases := []struct { name string responseBody []byte From 5c0ed6dfd90d1aadf11191385d902acf7872faa1 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Wed, 2 Oct 2019 23:46:00 +0000 Subject: [PATCH 06/10] fixes test cases for GetCatalogPage --- pkg/v1/remote/catalog_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/v1/remote/catalog_test.go b/pkg/v1/remote/catalog_test.go index 771277fad..0d20d1ee4 100644 --- a/pkg/v1/remote/catalog_test.go +++ b/pkg/v1/remote/catalog_test.go @@ -21,7 +21,6 @@ import ( "testing" "github.com/google/go-cmp/cmp" - "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" ) @@ -71,7 +70,7 @@ func TestGetCatalogPage(t *testing.T) { t.Fatalf("name.NewRegistry(%v) = %v", u.Host, err) } - repos, err := GetCatalog(reg, "", 100, WithAuthFromKeychain(authn.DefaultKeychain)) + repos, err := GetCatalogPage(reg, "", 100) if (err != nil) != tc.wantErr { t.Errorf("GetCatalog() wrong error: %v, want %v: %v\n", (err != nil), tc.wantErr, err) } From ba3476b12d0c48be97746861f1c85c07c4a28bae Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Mon, 21 Oct 2019 21:47:31 +0000 Subject: [PATCH 07/10] runs the codegen script and changes the command name to catalog from repos --- cmd/crane/cmd/catalog.go | 2 +- cmd/crane/doc/crane.md | 1 + cmd/crane/doc/crane_catalog.md | 22 +++++++ cmd/crane/doc/crane_repos.md | 22 +++++++ pkg/v1/fake/image.go | 114 ++++++++++++++++++++++++++++++++- pkg/v1/fake/index.go | 74 ++++++++++++++++++++- 6 files changed, 230 insertions(+), 5 deletions(-) create mode 100644 cmd/crane/doc/crane_catalog.md create mode 100644 cmd/crane/doc/crane_repos.md diff --git a/cmd/crane/cmd/catalog.go b/cmd/crane/cmd/catalog.go index 754323eff..ad0213299 100644 --- a/cmd/crane/cmd/catalog.go +++ b/cmd/crane/cmd/catalog.go @@ -27,7 +27,7 @@ func init() { Root.AddCommand(NewCmdGetCatalog()) } // NewCmdGetCatalog creates a new cobra.Command for the repos subcommand. func NewCmdGetCatalog() *cobra.Command { return &cobra.Command{ - Use: "repos", + Use: "catalog", Short: "List the repos in a registry", Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { diff --git a/cmd/crane/doc/crane.md b/cmd/crane/doc/crane.md index 1debb7d15..ca5ec217f 100644 --- a/cmd/crane/doc/crane.md +++ b/cmd/crane/doc/crane.md @@ -19,6 +19,7 @@ crane [flags] ### SEE ALSO * [crane append](crane_append.md) - Append contents of a tarball to a remote image +* [crane catalog](crane_catalog.md) - List the repos in a registry * [crane config](crane_config.md) - Get the config of an image * [crane copy](crane_copy.md) - Efficiently copy a remote image from src to dst * [crane delete](crane_delete.md) - Delete an image reference from its registry diff --git a/cmd/crane/doc/crane_catalog.md b/cmd/crane/doc/crane_catalog.md new file mode 100644 index 000000000..09b0262e9 --- /dev/null +++ b/cmd/crane/doc/crane_catalog.md @@ -0,0 +1,22 @@ +## crane catalog + +List the repos in a registry + +### Synopsis + +List the repos in a registry + +``` +crane catalog [flags] +``` + +### Options + +``` + -h, --help help for catalog +``` + +### SEE ALSO + +* [crane](crane.md) - Crane is a tool for managing container images + diff --git a/cmd/crane/doc/crane_repos.md b/cmd/crane/doc/crane_repos.md new file mode 100644 index 000000000..187557d3e --- /dev/null +++ b/cmd/crane/doc/crane_repos.md @@ -0,0 +1,22 @@ +## crane repos + +List the repos in a registry + +### Synopsis + +List the repos in a registry + +``` +crane repos [flags] +``` + +### Options + +``` + -h, --help help for repos +``` + +### SEE ALSO + +* [crane](crane.md) - Crane is a tool for managing container images + diff --git a/pkg/v1/fake/image.go b/pkg/v1/fake/image.go index fce17bc6d..fe63451e2 100644 --- a/pkg/v1/fake/image.go +++ b/pkg/v1/fake/image.go @@ -2,10 +2,10 @@ package fake import ( - sync "sync" + "sync" v1 "github.com/google/go-containerregistry/pkg/v1" - types "github.com/google/go-containerregistry/pkg/v1/types" + "github.com/google/go-containerregistry/pkg/v1/types" ) type FakeImage struct { @@ -170,7 +170,15 @@ func (fake *FakeImage) ConfigFileCallCount() int { return len(fake.configFileArgsForCall) } +func (fake *FakeImage) ConfigFileCalls(stub func() (*v1.ConfigFile, error)) { + fake.configFileMutex.Lock() + defer fake.configFileMutex.Unlock() + fake.ConfigFileStub = stub +} + func (fake *FakeImage) ConfigFileReturns(result1 *v1.ConfigFile, result2 error) { + fake.configFileMutex.Lock() + defer fake.configFileMutex.Unlock() fake.ConfigFileStub = nil fake.configFileReturns = struct { result1 *v1.ConfigFile @@ -179,6 +187,8 @@ func (fake *FakeImage) ConfigFileReturns(result1 *v1.ConfigFile, result2 error) } func (fake *FakeImage) ConfigFileReturnsOnCall(i int, result1 *v1.ConfigFile, result2 error) { + fake.configFileMutex.Lock() + defer fake.configFileMutex.Unlock() fake.ConfigFileStub = nil if fake.configFileReturnsOnCall == nil { fake.configFileReturnsOnCall = make(map[int]struct { @@ -215,7 +225,15 @@ func (fake *FakeImage) ConfigNameCallCount() int { return len(fake.configNameArgsForCall) } +func (fake *FakeImage) ConfigNameCalls(stub func() (v1.Hash, error)) { + fake.configNameMutex.Lock() + defer fake.configNameMutex.Unlock() + fake.ConfigNameStub = stub +} + func (fake *FakeImage) ConfigNameReturns(result1 v1.Hash, result2 error) { + fake.configNameMutex.Lock() + defer fake.configNameMutex.Unlock() fake.ConfigNameStub = nil fake.configNameReturns = struct { result1 v1.Hash @@ -224,6 +242,8 @@ func (fake *FakeImage) ConfigNameReturns(result1 v1.Hash, result2 error) { } func (fake *FakeImage) ConfigNameReturnsOnCall(i int, result1 v1.Hash, result2 error) { + fake.configNameMutex.Lock() + defer fake.configNameMutex.Unlock() fake.ConfigNameStub = nil if fake.configNameReturnsOnCall == nil { fake.configNameReturnsOnCall = make(map[int]struct { @@ -260,7 +280,15 @@ func (fake *FakeImage) DigestCallCount() int { return len(fake.digestArgsForCall) } +func (fake *FakeImage) DigestCalls(stub func() (v1.Hash, error)) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() + fake.DigestStub = stub +} + func (fake *FakeImage) DigestReturns(result1 v1.Hash, result2 error) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() fake.DigestStub = nil fake.digestReturns = struct { result1 v1.Hash @@ -269,6 +297,8 @@ func (fake *FakeImage) DigestReturns(result1 v1.Hash, result2 error) { } func (fake *FakeImage) DigestReturnsOnCall(i int, result1 v1.Hash, result2 error) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() fake.DigestStub = nil if fake.digestReturnsOnCall == nil { fake.digestReturnsOnCall = make(map[int]struct { @@ -306,6 +336,12 @@ func (fake *FakeImage) LayerByDiffIDCallCount() int { return len(fake.layerByDiffIDArgsForCall) } +func (fake *FakeImage) LayerByDiffIDCalls(stub func(v1.Hash) (v1.Layer, error)) { + fake.layerByDiffIDMutex.Lock() + defer fake.layerByDiffIDMutex.Unlock() + fake.LayerByDiffIDStub = stub +} + func (fake *FakeImage) LayerByDiffIDArgsForCall(i int) v1.Hash { fake.layerByDiffIDMutex.RLock() defer fake.layerByDiffIDMutex.RUnlock() @@ -314,6 +350,8 @@ func (fake *FakeImage) LayerByDiffIDArgsForCall(i int) v1.Hash { } func (fake *FakeImage) LayerByDiffIDReturns(result1 v1.Layer, result2 error) { + fake.layerByDiffIDMutex.Lock() + defer fake.layerByDiffIDMutex.Unlock() fake.LayerByDiffIDStub = nil fake.layerByDiffIDReturns = struct { result1 v1.Layer @@ -322,6 +360,8 @@ func (fake *FakeImage) LayerByDiffIDReturns(result1 v1.Layer, result2 error) { } func (fake *FakeImage) LayerByDiffIDReturnsOnCall(i int, result1 v1.Layer, result2 error) { + fake.layerByDiffIDMutex.Lock() + defer fake.layerByDiffIDMutex.Unlock() fake.LayerByDiffIDStub = nil if fake.layerByDiffIDReturnsOnCall == nil { fake.layerByDiffIDReturnsOnCall = make(map[int]struct { @@ -359,6 +399,12 @@ func (fake *FakeImage) LayerByDigestCallCount() int { return len(fake.layerByDigestArgsForCall) } +func (fake *FakeImage) LayerByDigestCalls(stub func(v1.Hash) (v1.Layer, error)) { + fake.layerByDigestMutex.Lock() + defer fake.layerByDigestMutex.Unlock() + fake.LayerByDigestStub = stub +} + func (fake *FakeImage) LayerByDigestArgsForCall(i int) v1.Hash { fake.layerByDigestMutex.RLock() defer fake.layerByDigestMutex.RUnlock() @@ -367,6 +413,8 @@ func (fake *FakeImage) LayerByDigestArgsForCall(i int) v1.Hash { } func (fake *FakeImage) LayerByDigestReturns(result1 v1.Layer, result2 error) { + fake.layerByDigestMutex.Lock() + defer fake.layerByDigestMutex.Unlock() fake.LayerByDigestStub = nil fake.layerByDigestReturns = struct { result1 v1.Layer @@ -375,6 +423,8 @@ func (fake *FakeImage) LayerByDigestReturns(result1 v1.Layer, result2 error) { } func (fake *FakeImage) LayerByDigestReturnsOnCall(i int, result1 v1.Layer, result2 error) { + fake.layerByDigestMutex.Lock() + defer fake.layerByDigestMutex.Unlock() fake.LayerByDigestStub = nil if fake.layerByDigestReturnsOnCall == nil { fake.layerByDigestReturnsOnCall = make(map[int]struct { @@ -411,7 +461,15 @@ func (fake *FakeImage) LayersCallCount() int { return len(fake.layersArgsForCall) } +func (fake *FakeImage) LayersCalls(stub func() ([]v1.Layer, error)) { + fake.layersMutex.Lock() + defer fake.layersMutex.Unlock() + fake.LayersStub = stub +} + func (fake *FakeImage) LayersReturns(result1 []v1.Layer, result2 error) { + fake.layersMutex.Lock() + defer fake.layersMutex.Unlock() fake.LayersStub = nil fake.layersReturns = struct { result1 []v1.Layer @@ -420,6 +478,8 @@ func (fake *FakeImage) LayersReturns(result1 []v1.Layer, result2 error) { } func (fake *FakeImage) LayersReturnsOnCall(i int, result1 []v1.Layer, result2 error) { + fake.layersMutex.Lock() + defer fake.layersMutex.Unlock() fake.LayersStub = nil if fake.layersReturnsOnCall == nil { fake.layersReturnsOnCall = make(map[int]struct { @@ -456,7 +516,15 @@ func (fake *FakeImage) ManifestCallCount() int { return len(fake.manifestArgsForCall) } +func (fake *FakeImage) ManifestCalls(stub func() (*v1.Manifest, error)) { + fake.manifestMutex.Lock() + defer fake.manifestMutex.Unlock() + fake.ManifestStub = stub +} + func (fake *FakeImage) ManifestReturns(result1 *v1.Manifest, result2 error) { + fake.manifestMutex.Lock() + defer fake.manifestMutex.Unlock() fake.ManifestStub = nil fake.manifestReturns = struct { result1 *v1.Manifest @@ -465,6 +533,8 @@ func (fake *FakeImage) ManifestReturns(result1 *v1.Manifest, result2 error) { } func (fake *FakeImage) ManifestReturnsOnCall(i int, result1 *v1.Manifest, result2 error) { + fake.manifestMutex.Lock() + defer fake.manifestMutex.Unlock() fake.ManifestStub = nil if fake.manifestReturnsOnCall == nil { fake.manifestReturnsOnCall = make(map[int]struct { @@ -501,7 +571,15 @@ func (fake *FakeImage) MediaTypeCallCount() int { return len(fake.mediaTypeArgsForCall) } +func (fake *FakeImage) MediaTypeCalls(stub func() (types.MediaType, error)) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() + fake.MediaTypeStub = stub +} + func (fake *FakeImage) MediaTypeReturns(result1 types.MediaType, result2 error) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() fake.MediaTypeStub = nil fake.mediaTypeReturns = struct { result1 types.MediaType @@ -510,6 +588,8 @@ func (fake *FakeImage) MediaTypeReturns(result1 types.MediaType, result2 error) } func (fake *FakeImage) MediaTypeReturnsOnCall(i int, result1 types.MediaType, result2 error) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() fake.MediaTypeStub = nil if fake.mediaTypeReturnsOnCall == nil { fake.mediaTypeReturnsOnCall = make(map[int]struct { @@ -546,7 +626,15 @@ func (fake *FakeImage) RawConfigFileCallCount() int { return len(fake.rawConfigFileArgsForCall) } +func (fake *FakeImage) RawConfigFileCalls(stub func() ([]byte, error)) { + fake.rawConfigFileMutex.Lock() + defer fake.rawConfigFileMutex.Unlock() + fake.RawConfigFileStub = stub +} + func (fake *FakeImage) RawConfigFileReturns(result1 []byte, result2 error) { + fake.rawConfigFileMutex.Lock() + defer fake.rawConfigFileMutex.Unlock() fake.RawConfigFileStub = nil fake.rawConfigFileReturns = struct { result1 []byte @@ -555,6 +643,8 @@ func (fake *FakeImage) RawConfigFileReturns(result1 []byte, result2 error) { } func (fake *FakeImage) RawConfigFileReturnsOnCall(i int, result1 []byte, result2 error) { + fake.rawConfigFileMutex.Lock() + defer fake.rawConfigFileMutex.Unlock() fake.RawConfigFileStub = nil if fake.rawConfigFileReturnsOnCall == nil { fake.rawConfigFileReturnsOnCall = make(map[int]struct { @@ -591,7 +681,15 @@ func (fake *FakeImage) RawManifestCallCount() int { return len(fake.rawManifestArgsForCall) } +func (fake *FakeImage) RawManifestCalls(stub func() ([]byte, error)) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() + fake.RawManifestStub = stub +} + func (fake *FakeImage) RawManifestReturns(result1 []byte, result2 error) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() fake.RawManifestStub = nil fake.rawManifestReturns = struct { result1 []byte @@ -600,6 +698,8 @@ func (fake *FakeImage) RawManifestReturns(result1 []byte, result2 error) { } func (fake *FakeImage) RawManifestReturnsOnCall(i int, result1 []byte, result2 error) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() fake.RawManifestStub = nil if fake.rawManifestReturnsOnCall == nil { fake.rawManifestReturnsOnCall = make(map[int]struct { @@ -636,7 +736,15 @@ func (fake *FakeImage) SizeCallCount() int { return len(fake.sizeArgsForCall) } +func (fake *FakeImage) SizeCalls(stub func() (int64, error)) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() + fake.SizeStub = stub +} + func (fake *FakeImage) SizeReturns(result1 int64, result2 error) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() fake.SizeStub = nil fake.sizeReturns = struct { result1 int64 @@ -645,6 +753,8 @@ func (fake *FakeImage) SizeReturns(result1 int64, result2 error) { } func (fake *FakeImage) SizeReturnsOnCall(i int, result1 int64, result2 error) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() fake.SizeStub = nil if fake.sizeReturnsOnCall == nil { fake.sizeReturnsOnCall = make(map[int]struct { diff --git a/pkg/v1/fake/index.go b/pkg/v1/fake/index.go index 1e1d1eae8..614c4aadf 100644 --- a/pkg/v1/fake/index.go +++ b/pkg/v1/fake/index.go @@ -2,10 +2,10 @@ package fake import ( - sync "sync" + "sync" v1 "github.com/google/go-containerregistry/pkg/v1" - types "github.com/google/go-containerregistry/pkg/v1/types" + "github.com/google/go-containerregistry/pkg/v1/types" ) type FakeImageIndex struct { @@ -122,7 +122,15 @@ func (fake *FakeImageIndex) DigestCallCount() int { return len(fake.digestArgsForCall) } +func (fake *FakeImageIndex) DigestCalls(stub func() (v1.Hash, error)) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() + fake.DigestStub = stub +} + func (fake *FakeImageIndex) DigestReturns(result1 v1.Hash, result2 error) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() fake.DigestStub = nil fake.digestReturns = struct { result1 v1.Hash @@ -131,6 +139,8 @@ func (fake *FakeImageIndex) DigestReturns(result1 v1.Hash, result2 error) { } func (fake *FakeImageIndex) DigestReturnsOnCall(i int, result1 v1.Hash, result2 error) { + fake.digestMutex.Lock() + defer fake.digestMutex.Unlock() fake.DigestStub = nil if fake.digestReturnsOnCall == nil { fake.digestReturnsOnCall = make(map[int]struct { @@ -168,6 +178,12 @@ func (fake *FakeImageIndex) ImageCallCount() int { return len(fake.imageArgsForCall) } +func (fake *FakeImageIndex) ImageCalls(stub func(v1.Hash) (v1.Image, error)) { + fake.imageMutex.Lock() + defer fake.imageMutex.Unlock() + fake.ImageStub = stub +} + func (fake *FakeImageIndex) ImageArgsForCall(i int) v1.Hash { fake.imageMutex.RLock() defer fake.imageMutex.RUnlock() @@ -176,6 +192,8 @@ func (fake *FakeImageIndex) ImageArgsForCall(i int) v1.Hash { } func (fake *FakeImageIndex) ImageReturns(result1 v1.Image, result2 error) { + fake.imageMutex.Lock() + defer fake.imageMutex.Unlock() fake.ImageStub = nil fake.imageReturns = struct { result1 v1.Image @@ -184,6 +202,8 @@ func (fake *FakeImageIndex) ImageReturns(result1 v1.Image, result2 error) { } func (fake *FakeImageIndex) ImageReturnsOnCall(i int, result1 v1.Image, result2 error) { + fake.imageMutex.Lock() + defer fake.imageMutex.Unlock() fake.ImageStub = nil if fake.imageReturnsOnCall == nil { fake.imageReturnsOnCall = make(map[int]struct { @@ -221,6 +241,12 @@ func (fake *FakeImageIndex) ImageIndexCallCount() int { return len(fake.imageIndexArgsForCall) } +func (fake *FakeImageIndex) ImageIndexCalls(stub func(v1.Hash) (v1.ImageIndex, error)) { + fake.imageIndexMutex.Lock() + defer fake.imageIndexMutex.Unlock() + fake.ImageIndexStub = stub +} + func (fake *FakeImageIndex) ImageIndexArgsForCall(i int) v1.Hash { fake.imageIndexMutex.RLock() defer fake.imageIndexMutex.RUnlock() @@ -229,6 +255,8 @@ func (fake *FakeImageIndex) ImageIndexArgsForCall(i int) v1.Hash { } func (fake *FakeImageIndex) ImageIndexReturns(result1 v1.ImageIndex, result2 error) { + fake.imageIndexMutex.Lock() + defer fake.imageIndexMutex.Unlock() fake.ImageIndexStub = nil fake.imageIndexReturns = struct { result1 v1.ImageIndex @@ -237,6 +265,8 @@ func (fake *FakeImageIndex) ImageIndexReturns(result1 v1.ImageIndex, result2 err } func (fake *FakeImageIndex) ImageIndexReturnsOnCall(i int, result1 v1.ImageIndex, result2 error) { + fake.imageIndexMutex.Lock() + defer fake.imageIndexMutex.Unlock() fake.ImageIndexStub = nil if fake.imageIndexReturnsOnCall == nil { fake.imageIndexReturnsOnCall = make(map[int]struct { @@ -273,7 +303,15 @@ func (fake *FakeImageIndex) IndexManifestCallCount() int { return len(fake.indexManifestArgsForCall) } +func (fake *FakeImageIndex) IndexManifestCalls(stub func() (*v1.IndexManifest, error)) { + fake.indexManifestMutex.Lock() + defer fake.indexManifestMutex.Unlock() + fake.IndexManifestStub = stub +} + func (fake *FakeImageIndex) IndexManifestReturns(result1 *v1.IndexManifest, result2 error) { + fake.indexManifestMutex.Lock() + defer fake.indexManifestMutex.Unlock() fake.IndexManifestStub = nil fake.indexManifestReturns = struct { result1 *v1.IndexManifest @@ -282,6 +320,8 @@ func (fake *FakeImageIndex) IndexManifestReturns(result1 *v1.IndexManifest, resu } func (fake *FakeImageIndex) IndexManifestReturnsOnCall(i int, result1 *v1.IndexManifest, result2 error) { + fake.indexManifestMutex.Lock() + defer fake.indexManifestMutex.Unlock() fake.IndexManifestStub = nil if fake.indexManifestReturnsOnCall == nil { fake.indexManifestReturnsOnCall = make(map[int]struct { @@ -318,7 +358,15 @@ func (fake *FakeImageIndex) MediaTypeCallCount() int { return len(fake.mediaTypeArgsForCall) } +func (fake *FakeImageIndex) MediaTypeCalls(stub func() (types.MediaType, error)) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() + fake.MediaTypeStub = stub +} + func (fake *FakeImageIndex) MediaTypeReturns(result1 types.MediaType, result2 error) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() fake.MediaTypeStub = nil fake.mediaTypeReturns = struct { result1 types.MediaType @@ -327,6 +375,8 @@ func (fake *FakeImageIndex) MediaTypeReturns(result1 types.MediaType, result2 er } func (fake *FakeImageIndex) MediaTypeReturnsOnCall(i int, result1 types.MediaType, result2 error) { + fake.mediaTypeMutex.Lock() + defer fake.mediaTypeMutex.Unlock() fake.MediaTypeStub = nil if fake.mediaTypeReturnsOnCall == nil { fake.mediaTypeReturnsOnCall = make(map[int]struct { @@ -363,7 +413,15 @@ func (fake *FakeImageIndex) RawManifestCallCount() int { return len(fake.rawManifestArgsForCall) } +func (fake *FakeImageIndex) RawManifestCalls(stub func() ([]byte, error)) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() + fake.RawManifestStub = stub +} + func (fake *FakeImageIndex) RawManifestReturns(result1 []byte, result2 error) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() fake.RawManifestStub = nil fake.rawManifestReturns = struct { result1 []byte @@ -372,6 +430,8 @@ func (fake *FakeImageIndex) RawManifestReturns(result1 []byte, result2 error) { } func (fake *FakeImageIndex) RawManifestReturnsOnCall(i int, result1 []byte, result2 error) { + fake.rawManifestMutex.Lock() + defer fake.rawManifestMutex.Unlock() fake.RawManifestStub = nil if fake.rawManifestReturnsOnCall == nil { fake.rawManifestReturnsOnCall = make(map[int]struct { @@ -408,7 +468,15 @@ func (fake *FakeImageIndex) SizeCallCount() int { return len(fake.sizeArgsForCall) } +func (fake *FakeImageIndex) SizeCalls(stub func() (int64, error)) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() + fake.SizeStub = stub +} + func (fake *FakeImageIndex) SizeReturns(result1 int64, result2 error) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() fake.SizeStub = nil fake.sizeReturns = struct { result1 int64 @@ -417,6 +485,8 @@ func (fake *FakeImageIndex) SizeReturns(result1 int64, result2 error) { } func (fake *FakeImageIndex) SizeReturnsOnCall(i int, result1 int64, result2 error) { + fake.sizeMutex.Lock() + defer fake.sizeMutex.Unlock() fake.SizeStub = nil if fake.sizeReturnsOnCall == nil { fake.sizeReturnsOnCall = make(map[int]struct { From 4edb3623a7f9ad1ac1a8bd5c766024e6219f71fa Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Tue, 22 Oct 2019 16:44:43 +0000 Subject: [PATCH 08/10] addresses review comments --- cmd/crane/cmd/catalog.go | 4 ++-- cmd/crane/doc/crane_repos.md | 22 ---------------------- hack/update-code-gen.sh | 4 ++-- pkg/crane/catalog.go | 4 +--- pkg/v1/remote/catalog.go | 2 +- vendor/k8s.io/code-generator | 1 + 6 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 cmd/crane/doc/crane_repos.md create mode 160000 vendor/k8s.io/code-generator diff --git a/cmd/crane/cmd/catalog.go b/cmd/crane/cmd/catalog.go index ad0213299..a3abfbe8f 100644 --- a/cmd/crane/cmd/catalog.go +++ b/cmd/crane/cmd/catalog.go @@ -22,10 +22,10 @@ import ( "github.com/spf13/cobra" ) -func init() { Root.AddCommand(NewCmdGetCatalog()) } +func init() { Root.AddCommand(NewCmdCatalog()) } // NewCmdGetCatalog creates a new cobra.Command for the repos subcommand. -func NewCmdGetCatalog() *cobra.Command { +func NewCmdCatalog() *cobra.Command { return &cobra.Command{ Use: "catalog", Short: "List the repos in a registry", diff --git a/cmd/crane/doc/crane_repos.md b/cmd/crane/doc/crane_repos.md deleted file mode 100644 index 187557d3e..000000000 --- a/cmd/crane/doc/crane_repos.md +++ /dev/null @@ -1,22 +0,0 @@ -## crane repos - -List the repos in a registry - -### Synopsis - -List the repos in a registry - -``` -crane repos [flags] -``` - -### Options - -``` - -h, --help help for repos -``` - -### SEE ALSO - -* [crane](crane.md) - Crane is a tool for managing container images - diff --git a/hack/update-code-gen.sh b/hack/update-code-gen.sh index c9579371f..2e81feb4c 100755 --- a/hack/update-code-gen.sh +++ b/hack/update-code-gen.sh @@ -28,7 +28,7 @@ export GOPATH=$(go env GOPATH) export PATH="${GOPATH}/bin:${PATH}" -go install ./vendor/k8s.io/code-generator/cmd/deepcopy-gen -go install ./vendor/github.com/maxbrunsfeld/counterfeiter +go install k8s.io/code-generator/cmd/deepcopy-gen +go install github.com/maxbrunsfeld/counterfeiter go run $PROJECT_ROOT/cmd/crane/help/main.go --dir=$PROJECT_ROOT/cmd/crane/doc/ go generate ./... diff --git a/pkg/crane/catalog.go b/pkg/crane/catalog.go index 0399e3dd8..29a9bf471 100644 --- a/pkg/crane/catalog.go +++ b/pkg/crane/catalog.go @@ -20,7 +20,7 @@ import ( "github.com/google/go-containerregistry/pkg/v1/remote" ) -// GetCatalog returns the repositories in a registry's catalog +// GetCatalog returns the repositories in a registry's catalog. func GetCatalog(src string) (res []string, err error) { reg, err := name.NewRegistry(src) if err != nil { @@ -30,7 +30,6 @@ func GetCatalog(src string) (res []string, err error) { n := 100 last := "" for { - page, err := remote.GetCatalogPage(reg, last, n, remote.WithAuthFromKeychain(authn.DefaultKeychain)) if err != nil { return nil, err @@ -44,7 +43,6 @@ func GetCatalog(src string) (res []string, err error) { if len(page) < n { break } - } return res, nil diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 975c548f9..3aa13b2b3 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -28,7 +28,7 @@ type catalog struct { Repos []string `json:"repositories"` } -// GetCatalogPage calls /_catalog, returning the list of repositories on the registry +// GetCatalogPage calls /_catalog, returning the list of repositories on the registry. func GetCatalogPage(target name.Registry, last string, n int, options ...Option) ([]string, error) { o, err := makeOptions(target, options...) if err != nil { diff --git a/vendor/k8s.io/code-generator b/vendor/k8s.io/code-generator new file mode 160000 index 000000000..0b22993d2 --- /dev/null +++ b/vendor/k8s.io/code-generator @@ -0,0 +1 @@ +Subproject commit 0b22993d207cb22c0d896ef238a1ac77447278d0 From 7f18e3213352f67c87ddbbe67d5735bef0868307 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Tue, 22 Oct 2019 16:45:58 +0000 Subject: [PATCH 09/10] addresses another supernit --- pkg/v1/remote/catalog_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/v1/remote/catalog_test.go b/pkg/v1/remote/catalog_test.go index 0d20d1ee4..7166e36f9 100644 --- a/pkg/v1/remote/catalog_test.go +++ b/pkg/v1/remote/catalog_test.go @@ -40,7 +40,7 @@ func TestGetCatalogPage(t *testing.T) { responseBody: []byte("notjson"), wantErr: true, }} - //TODO: add test cases for pagination + // TODO: add test cases for pagination for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { From 9eeee72f6dcd1621bbbd0a620387af2b2d0ab629 Mon Sep 17 00:00:00 2001 From: Joshua Makinen Date: Fri, 25 Oct 2019 18:54:12 +0000 Subject: [PATCH 10/10] fixes the hopefully last round of nits to get this catalog functionality in!(no worries if I'm still not there tho) --- cmd/crane/cmd/catalog.go | 6 +++--- pkg/crane/catalog.go | 8 ++++---- pkg/v1/remote/catalog.go | 6 +++--- pkg/v1/remote/catalog_test.go | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/crane/cmd/catalog.go b/cmd/crane/cmd/catalog.go index a3abfbe8f..cf38acb48 100644 --- a/cmd/crane/cmd/catalog.go +++ b/cmd/crane/cmd/catalog.go @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC All Rights Reserved. +// Copyright 2019 Google LLC All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( func init() { Root.AddCommand(NewCmdCatalog()) } -// NewCmdGetCatalog creates a new cobra.Command for the repos subcommand. +// NewCmdCatalog creates a new cobra.Command for the repos subcommand. func NewCmdCatalog() *cobra.Command { return &cobra.Command{ Use: "catalog", @@ -32,7 +32,7 @@ func NewCmdCatalog() *cobra.Command { Args: cobra.ExactArgs(1), Run: func(_ *cobra.Command, args []string) { reg := args[0] - repos, err := crane.GetCatalog(reg) + repos, err := crane.Catalog(reg) if err != nil { log.Fatalf("reading repos for %s: %v", reg, err) } diff --git a/pkg/crane/catalog.go b/pkg/crane/catalog.go index 29a9bf471..6df30459b 100644 --- a/pkg/crane/catalog.go +++ b/pkg/crane/catalog.go @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC All Rights Reserved. +// Copyright 2019 Google LLC All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -20,8 +20,8 @@ import ( "github.com/google/go-containerregistry/pkg/v1/remote" ) -// GetCatalog returns the repositories in a registry's catalog. -func GetCatalog(src string) (res []string, err error) { +// Catalog returns the repositories in a registry's catalog. +func Catalog(src string) (res []string, err error) { reg, err := name.NewRegistry(src) if err != nil { return nil, err @@ -30,7 +30,7 @@ func GetCatalog(src string) (res []string, err error) { n := 100 last := "" for { - page, err := remote.GetCatalogPage(reg, last, n, remote.WithAuthFromKeychain(authn.DefaultKeychain)) + page, err := remote.CatalogPage(reg, last, n, remote.WithAuthFromKeychain(authn.DefaultKeychain)) if err != nil { return nil, err } diff --git a/pkg/v1/remote/catalog.go b/pkg/v1/remote/catalog.go index 3aa13b2b3..da9c73535 100644 --- a/pkg/v1/remote/catalog.go +++ b/pkg/v1/remote/catalog.go @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC All Rights Reserved. +// Copyright 2019 Google LLC All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -28,8 +28,8 @@ type catalog struct { Repos []string `json:"repositories"` } -// GetCatalogPage calls /_catalog, returning the list of repositories on the registry. -func GetCatalogPage(target name.Registry, last string, n int, options ...Option) ([]string, error) { +// CatalogPage calls /_catalog, returning the list of repositories on the registry. +func CatalogPage(target name.Registry, last string, n int, options ...Option) ([]string, error) { o, err := makeOptions(target, options...) if err != nil { return nil, err diff --git a/pkg/v1/remote/catalog_test.go b/pkg/v1/remote/catalog_test.go index 7166e36f9..dbd91b985 100644 --- a/pkg/v1/remote/catalog_test.go +++ b/pkg/v1/remote/catalog_test.go @@ -1,4 +1,4 @@ -// Copyright 2018 Google LLC All Rights Reserved. +// Copyright 2019 Google LLC All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import ( "github.com/google/go-containerregistry/pkg/name" ) -func TestGetCatalogPage(t *testing.T) { +func TestCatalogPage(t *testing.T) { cases := []struct { name string responseBody []byte @@ -70,13 +70,13 @@ func TestGetCatalogPage(t *testing.T) { t.Fatalf("name.NewRegistry(%v) = %v", u.Host, err) } - repos, err := GetCatalogPage(reg, "", 100) + repos, err := CatalogPage(reg, "", 100) if (err != nil) != tc.wantErr { - t.Errorf("GetCatalog() wrong error: %v, want %v: %v\n", (err != nil), tc.wantErr, err) + t.Errorf("Catalog() wrong error: %v, want %v: %v\n", (err != nil), tc.wantErr, err) } if diff := cmp.Diff(tc.wantRepos, repos); diff != "" { - t.Errorf("GetCatalog() wrong repos (-want +got) = %s", diff) + t.Errorf("Catalog() wrong repos (-want +got) = %s", diff) } }) }