From 21d6ed0fcad41bd460d45b04802567c99f7d7c19 Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang <103478229+wangxiaoxuan273@users.noreply.github.com> Date: Tue, 13 Sep 2022 16:22:44 +0800 Subject: [PATCH] test: add interface tests for Repository, blobStore and manifestStore (#313) Signed-off-by: wangxiaoxuan273 --- registry/remote/interface_test.go | 38 ++++++++++++++++++++++++++++++ registry/remote/repository_test.go | 19 +++++++-------- 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 registry/remote/interface_test.go diff --git a/registry/remote/interface_test.go b/registry/remote/interface_test.go new file mode 100644 index 00000000..be5a88e0 --- /dev/null +++ b/registry/remote/interface_test.go @@ -0,0 +1,38 @@ +/* +Copyright The ORAS 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 remote_test + +import ( + "testing" + + "oras.land/oras-go/v2" + "oras.land/oras-go/v2/internal/interfaces" + "oras.land/oras-go/v2/registry" + "oras.land/oras-go/v2/registry/remote" +) + +func TestRepositoryInterface(t *testing.T) { + var repo interface{} = &remote.Repository{} + if _, ok := repo.(registry.Repository); !ok { + t.Error("&Repository{} does not conform registry.Repository") + } + if _, ok := repo.(oras.GraphTarget); !ok { + t.Error("&Repository{} does not conform oras.GraphTarget") + } + if _, ok := repo.(interfaces.ReferenceParser); !ok { + t.Error("&Repository{} does not conform interfaces.ReferenceParser") + } +} diff --git a/registry/remote/repository_test.go b/registry/remote/repository_test.go index 4ff18ff6..022fce21 100644 --- a/registry/remote/repository_test.go +++ b/registry/remote/repository_test.go @@ -36,9 +36,9 @@ import ( "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1" - "oras.land/oras-go/v2/content" "oras.land/oras-go/v2/errdef" "oras.land/oras-go/v2/internal/descriptor" + "oras.land/oras-go/v2/internal/interfaces" "oras.land/oras-go/v2/registry" "oras.land/oras-go/v2/registry/remote/auth" ) @@ -118,16 +118,6 @@ func getTestIOStructMapForGetDescriptorClass() map[string]testIOStruct { } } -func TestRepositoryInterface(t *testing.T) { - var repo interface{} = &Repository{} - if _, ok := repo.(registry.Repository); !ok { - t.Error("&Repository{} does not conform registry.Repository") - } - if _, ok := repo.(content.GraphStorage); !ok { - t.Error("&Repository{} does not conform content.GraphStorage") - } -} - func TestRepository_Fetch(t *testing.T) { blob := []byte("hello world") blobDesc := ocispec.Descriptor{ @@ -2455,6 +2445,13 @@ func Test_generateBlobDescriptorWithVariousDockerContentDigestHeaders(t *testing } } +func TestManifestStoreInterface(t *testing.T) { + var ms interface{} = &manifestStore{} + if _, ok := ms.(interfaces.ReferenceParser); !ok { + t.Error("&manifestStore{} does not conform interfaces.ReferenceParser") + } +} + func Test_ManifestStore_Fetch(t *testing.T) { manifest := []byte(`{"layers":[]}`) manifestDesc := ocispec.Descriptor{