From 2d16a8135b13cfe092501e72ecce3808bfb419f2 Mon Sep 17 00:00:00 2001 From: Alex Sears Date: Wed, 24 Feb 2021 14:38:37 -0500 Subject: [PATCH 1/2] initialize registry client in oci getter Signed-off-by: Alex Sears --- pkg/getter/ocigetter.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/getter/ocigetter.go b/pkg/getter/ocigetter.go index d8fd53862..3f85b9862 100644 --- a/pkg/getter/ocigetter.go +++ b/pkg/getter/ocigetter.go @@ -58,10 +58,19 @@ func (g *OCIGetter) get(href string) (*bytes.Buffer, error) { } // NewOCIGetter constructs a valid http/https client as a Getter -func NewOCIGetter(options ...Option) (Getter, error) { - var client OCIGetter +func NewOCIGetter(ops ...Option) (Getter, error) { + registryClient, err := registry.NewClient() + if err != nil { + return nil, err + } - for _, opt := range options { + client := OCIGetter{ + opts: options{ + registryClient: registryClient, + }, + } + + for _, opt := range ops { opt(&client.opts) } From 1c377f8c6204983ca37e8b7b2048669dfbef8b9e Mon Sep 17 00:00:00 2001 From: Alex Sears Date: Wed, 24 Feb 2021 18:02:19 -0500 Subject: [PATCH 2/2] add test to ensure OCIGetter registryClient is set Signed-off-by: Alex Sears --- pkg/getter/ocigetter_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pkg/getter/ocigetter_test.go diff --git a/pkg/getter/ocigetter_test.go b/pkg/getter/ocigetter_test.go new file mode 100644 index 000000000..fc548b7a6 --- /dev/null +++ b/pkg/getter/ocigetter_test.go @@ -0,0 +1,30 @@ +/* +Copyright The Helm Authors. +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 getter + +import ( + "testing" +) + +func TestNewOCIGetter(t *testing.T) { + testfn := func(ops *options) { + if ops.registryClient == nil { + t.Fatalf("the OCIGetter's registryClient should not be null") + } + } + + NewOCIGetter(testfn) +}