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
|
|
|
{
|
2015-01-14 20:34:47 +01:00
|
|
|
spec: manifestRevisionPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
revision: "sha256:abcdef0123456789",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/revisions/sha256/abcdef0123456789",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestRevisionLinkPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
revision: "sha256:abcdef0123456789",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/revisions/sha256/abcdef0123456789/link",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestSignatureLinkPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
revision: "sha256:abcdef0123456789",
|
|
|
|
signature: "sha256:abcdef0123456789",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/revisions/sha256/abcdef0123456789/signatures/sha256/abcdef0123456789/link",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestSignaturesPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
revision: "sha256:abcdef0123456789",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/revisions/sha256/abcdef0123456789/signatures",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestTagsPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/tags",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestTagPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
tag: "thetag",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/tags/thetag",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestTagCurrentPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
tag: "thetag",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/tags/thetag/current/link",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestTagIndexPathSpec{
|
2014-11-22 02:04:35 +01:00
|
|
|
name: "foo/bar",
|
|
|
|
tag: "thetag",
|
|
|
|
},
|
2015-01-14 20:34:47 +01:00
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/tags/thetag/index",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: manifestTagIndexEntryPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
tag: "thetag",
|
|
|
|
revision: "sha256:abcdef0123456789",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/manifests/tags/thetag/index/sha256/abcdef0123456789/link",
|
2014-11-22 02:04:35 +01:00
|
|
|
},
|
2014-11-14 00:16:54 +01:00
|
|
|
{
|
|
|
|
spec: layerLinkPathSpec{
|
|
|
|
name: "foo/bar",
|
2015-01-14 20:34:47 +01:00
|
|
|
digest: "tarsum.v1+test:abcdef",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2015-01-14 20:34:47 +01:00
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/layers/tarsum/v1/test/abcdef/link",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
|
|
|
{
|
2015-01-14 20:34:47 +01:00
|
|
|
spec: blobDataPathSpec{
|
2014-11-25 01:21:02 +01:00
|
|
|
digest: digest.Digest("tarsum.dev+sha512:abcdefabcdefabcdef908909909"),
|
|
|
|
},
|
2015-01-14 20:34:47 +01:00
|
|
|
expected: "/pathmapper-test/blobs/tarsum/dev/sha512/ab/abcdefabcdefabcdef908909909/data",
|
2014-11-25 01:21:02 +01:00
|
|
|
},
|
|
|
|
{
|
2015-01-14 20:34:47 +01:00
|
|
|
spec: blobDataPathSpec{
|
2014-11-25 01:21:02 +01:00
|
|
|
digest: digest.Digest("tarsum.v1+sha256:abcdefabcdefabcdef908909909"),
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2015-01-14 20:34:47 +01:00
|
|
|
expected: "/pathmapper-test/blobs/tarsum/v1/sha256/ab/abcdefabcdefabcdef908909909/data",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2015-01-14 20:34:47 +01:00
|
|
|
|
2014-11-14 00:16:54 +01:00
|
|
|
{
|
2015-01-08 23:10:08 +01:00
|
|
|
spec: uploadDataPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
uuid: "asdf-asdf-asdf-adsf",
|
|
|
|
},
|
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/uploads/asdf-asdf-asdf-adsf/data",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
spec: uploadStartedAtPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
uuid: "asdf-asdf-asdf-adsf",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
2015-01-08 23:10:08 +01:00
|
|
|
expected: "/pathmapper-test/repositories/foo/bar/uploads/asdf-asdf-asdf-adsf/startedat",
|
2014-11-14 00:16:54 +01:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
p, err := pm.path(testcase.spec)
|
|
|
|
if err != nil {
|
2015-01-14 20:34:47 +01:00
|
|
|
t.Fatalf("unexpected generating path (%T): %v", testcase.spec, err)
|
2014-11-14 00:16:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if p != testcase.expected {
|
2015-01-14 20:34:47 +01:00
|
|
|
t.Fatalf("unexpected path generated (%T): %q != %q", testcase.spec, p, testcase.expected)
|
2014-11-14 00:16:54 +01:00
|
|
|
}
|
|
|
|
}
|
2015-01-14 20:34:47 +01:00
|
|
|
|
|
|
|
// Add a few test cases to ensure we cover some errors
|
|
|
|
|
|
|
|
// Specify a path that requires a revision and get a digest validation error.
|
|
|
|
badpath, err := pm.path(manifestSignaturesPathSpec{
|
|
|
|
name: "foo/bar",
|
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected an error when mapping an invalid revision: %s", badpath)
|
|
|
|
}
|
|
|
|
|
2014-11-14 00:16:54 +01:00
|
|
|
}
|