Merge pull request #4283 from hs0210/work

Add unit test for func in remotes/docker/handler.go
This commit is contained in:
Akihiro Suda 2020-05-29 00:25:41 +09:00 committed by GitHub
commit 27f1e0d9ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,8 @@ package docker
import (
"reflect"
"testing"
"github.com/containerd/containerd/reference"
)
func TestAppendDistributionLabel(t *testing.T) {
@ -100,3 +102,31 @@ func TestCommonPrefixComponents(t *testing.T) {
}
}
}
func TestSelectRepositoryMountCandidate(t *testing.T) {
for _, tc := range []struct {
refspec reference.Spec
source map[string]string
expected string
}{
{
refspec: reference.Spec{},
source: map[string]string{"": ""},
expected: "",
},
{
refspec: reference.Spec{Locator: "user@host/path"},
source: map[string]string{"containerd.io/distribution.source.host": "foo,path,bar"},
expected: "bar",
},
{
refspec: reference.Spec{Locator: "user@host/path"},
source: map[string]string{"containerd.io/distribution.source.host": "foo,bar,path"},
expected: "bar",
},
} {
if got := selectRepositoryMountCandidate(tc.refspec, tc.source); !reflect.DeepEqual(got, tc.expected) {
t.Fatalf("expected %v, but got %v", tc.expected, got)
}
}
}