Merge pull request #4137 from hs0210/work

Add unit test for func in remotes/docker/handler.go
This commit is contained in:
Phil Estes 2020-04-02 12:24:58 -04:00 committed by GitHub
commit d8153b065a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,3 +72,31 @@ func TestDistributionSourceLabelKey(t *testing.T) {
t.Fatalf("expected %v, but got %v", expected, got)
}
}
func TestCommonPrefixComponents(t *testing.T) {
for _, tc := range []struct {
components []string
target string
expected int
}{
{
components: []string{"foo"},
target: "foo/bar",
expected: 1,
},
{
components: []string{"bar"},
target: "foo/bar",
expected: 0,
},
{
components: []string{"foo", "bar"},
target: "foo/bar",
expected: 2,
},
} {
if got := commonPrefixComponents(tc.components, tc.target); !reflect.DeepEqual(got, tc.expected) {
t.Fatalf("expected %v, but got %v", tc.expected, got)
}
}
}