Skip to content

Commit

Permalink
test: add interface tests for Repository, blobStore and manifestStore (
Browse files Browse the repository at this point in the history
…#313)

Signed-off-by: wangxiaoxuan273 <[email protected]>
  • Loading branch information
wangxiaoxuan273 authored Sep 13, 2022
1 parent a018d99 commit 21d6ed0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
38 changes: 38 additions & 0 deletions registry/remote/interface_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
19 changes: 8 additions & 11 deletions registry/remote/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 21d6ed0

Please sign in to comment.