2014-11-14 00:16:54 +01:00
|
|
|
package storage
|
|
|
|
|
2014-11-19 23:39:32 +01:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2014-12-24 01:01:38 +01:00
|
|
|
"github.com/docker/distribution/digest"
|
2014-11-19 23:39:32 +01:00
|
|
|
)
|
2014-11-14 00:16:54 +01:00
|
|
|
|
|
|
|
func TestPathMapper(t *testing.T) {
|
|
|
|
pm := &pathMapper{
|
|
|
|
root: "/pathmapper-test",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, testcase := range []struct {
|
|
|
|
spec pathSpec
|
|
|
|
expected string
|
|
|
|
err error
|
|
|
|
}{
|
2014-11-22 02:04:35 +01:00
|
|
|
{
|
|
|
|
spec: manifestPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
tag: "thetag",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/thetag",
|
|
|
|
},
|
2014-11-14 00:16:54 +01:00
|
|
|
{
|
|
|
|
spec: layerLinkPathSpec{
|
|
|
|
name: "foo/bar",
|
2014-11-19 23:39:32 +01:00
|
|
|
digest: digest.Digest("tarsum.v1+test:abcdef"),
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2014-11-25 01:21:02 +01:00
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/layers/tarsum/v1/test/ab/abcdef",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
|
|
|
{
|
2014-11-25 01:21:02 +01:00
|
|
|
spec: blobPathSpec{
|
|
|
|
digest: digest.Digest("tarsum.dev+sha512:abcdefabcdefabcdef908909909"),
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/blob/tarsum/dev/sha512/ab/abcdefabcdefabcdef908909909",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: blobPathSpec{
|
|
|
|
digest: digest.Digest("tarsum.v1+sha256:abcdefabcdefabcdef908909909"),
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2014-11-25 01:21:02 +01:00
|
|
|
expected: "/pathmapper-test/blob/tarsum/v1/sha256/ab/abcdefabcdefabcdef908909909",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: blobPathSpec{
|
2014-11-25 01:21:02 +01:00
|
|
|
digest: digest.Digest("tarsum+sha256:abcdefabcdefabcdef908909909"),
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2014-11-25 01:21:02 +01:00
|
|
|
expected: "/pathmapper-test/blob/tarsum/v0/sha256/ab/abcdefabcdefabcdef908909909",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|