Commit d4844efe authored by Kevin Atkinson's avatar Kevin Atkinson

Add support for NextToLast shard function.

parent ace251fd
......@@ -62,6 +62,15 @@ func Suffix(suffixLen int) ShardFunc {
}
}
func NextToLast(suffixLen int) ShardFunc {
padding := strings.Repeat("_", suffixLen+1)
return func(noslash string) string {
str := padding + noslash
offset := len(str) - suffixLen - 1
return str[offset : offset+suffixLen]
}
}
func (fs *Datastore) encode(key datastore.Key) (dir, file string) {
noslash := key.String()[1:]
dir = path.Join(fs.path, fs.getDir(noslash))
......
......@@ -33,6 +33,7 @@ func tempdir(t testing.TB) (path string, cleanup func()) {
func tryAllShardFuncs(t *testing.T, testFunc func(mkShardFunc, *testing.T)) {
t.Run("prefix", func(t *testing.T) { testFunc(flatfs.Prefix, t) })
t.Run("suffix", func(t *testing.T) { testFunc(flatfs.Suffix, t) })
t.Run("next-to-last", func(t *testing.T) { testFunc(flatfs.NextToLast, t) })
}
func TestPutBadValueType(t *testing.T) {
......@@ -230,6 +231,14 @@ func TestStorage(t *testing.T) {
dirFunc: flatfs.Suffix,
}, t)
})
t.Run("next-to-last", func(t *testing.T) {
testStorage(&params{
what: "next-to-last",
dir: "uu",
key: "quux",
dirFunc: flatfs.NextToLast,
}, t)
})
}
func testHasNotFound(dirFunc mkShardFunc, t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment