2014-11-13 23:16:54 +00:00
|
|
|
package storage
|
|
|
|
|
2014-11-19 22:39:32 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/docker/docker-registry/digest"
|
|
|
|
)
|
2014-11-13 23:16:54 +00:00
|
|
|
|
|
|
|
func TestPathMapper(t *testing.T) {
|
|
|
|
pm := &pathMapper{
|
|
|
|
root: "/pathmapper-test",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range []struct {
|
|
|
|
spec pathSpec
|
|
|
|
expected string
|
|
|
|
err error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
spec: layerLinkPathSpec{
|
|
|
|
name: "foo/bar",
|
2014-11-19 22:39:32 +00:00
|
|
|
digest: digest.Digest("tarsum.v1+test:abcdef"),
|
2014-11-13 23:16:54 +00:00
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/layers/tarsum/v1/test/abcdef",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: layerIndexLinkPathSpec{
|
2014-11-19 22:39:32 +00:00
|
|
|
digest: digest.Digest("tarsum.v1+test:abcdef"),
|
2014-11-13 23:16:54 +00:00
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/layerindex/tarsum/v1/test/abcdef",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: blobPathSpec{
|
|
|
|
alg: "sha512",
|
|
|
|
digest: "abcdefabcdefabcdef908909909",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/blob/sha512/ab/abcdefabcdefabcdef908909909",
|
|
|
|
},
|
|
|
|
} {
|
|
|
|
p, err := pm.path(testcase.spec)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p != testcase.expected {
|
|
|
|
t.Fatalf("unexpected path generated: %q != %q", p, testcase.expected)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|