Skip to content

Commit

Permalink
Merge pull request #4283 from hs0210/work
Browse files Browse the repository at this point in the history
Add unit test for func in remotes/docker/handler.go
  • Loading branch information
AkihiroSuda authored May 28, 2020
2 parents 137abe4 + 230cf6d commit 27f1e0d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions remotes/docker/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package docker
import (
"reflect"
"testing"

"github.com/containerd/containerd/reference"
)

func TestAppendDistributionLabel(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit 27f1e0d

Please sign in to comment.