Add unit test for func in remotes/docker/handler.go

Signed-off-by: Hu Shuai <hus.fnst@cn.fujitsu.com>
This commit is contained in:
Hu Shuai 2020-05-26 11:10:41 +08:00
parent 4cbf59db82
commit 230cf6deda

View File

@ -19,6 +19,8 @@ package docker
import ( import (
"reflect" "reflect"
"testing" "testing"
"github.com/containerd/containerd/reference"
) )
func TestAppendDistributionLabel(t *testing.T) { 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)
}
}
}