Initial implementation of storage layer path mapper

We've added a path mapper to support simple mapping between path objects used
in the storage layer and the underlying file system. The target of this is to
ensure that paths are only calculated in a single place and their format is
separated from the data that makes up the path components.

This commit only includes spec implementation to support layer reads. Further
specs will come along with their implementations.
This commit is contained in:
Stephen J Day 2014-11-13 15:16:54 -08:00
parent 0c999bd2da
commit 8e44c1d209
4 changed files with 231 additions and 0 deletions

45
storage/paths_test.go Normal file
View file

@ -0,0 +1,45 @@
package storage
import "testing"
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",
tarSum: "tarsum.v1+test:abcdef",
},
expected: "/pathmapper-test/repositories/foo/bar/layers/tarsum/v1/test/abcdef",
},
{
spec: layerIndexLinkPathSpec{
tarSum: "tarsum.v1+test:abcdef",
},
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)
}
}
}