Commit 9492e359 authored by Kevin Atkinson's avatar Kevin Atkinson

Always require the version string.

parent b49a06df
......@@ -41,9 +41,9 @@ var _ datastore.Datastore = (*Datastore)(nil)
type ShardFunc func(string) string
var (
ErrDatastoreExists = errors.New("Datastore already exist")
ErrDatastoreExists = errors.New("Datastore already exist")
ErrDatastoreDoesNotExist = errors.New("Datastore directory does not exist")
ErrShardingFileMissing = errors.New("SHARDING file not found in datastore")
ErrShardingFileMissing = errors.New("SHARDING file not found in datastore")
)
const IPFS_DEF_SHARD = "/repo/flatfs/shard/v1/next-to-last/2"
......
......@@ -33,16 +33,16 @@ func tempdir(t testing.TB) (path string, cleanup func()) {
}
func tryAllShardFuncs(t *testing.T, testFunc func(string, *testing.T)) {
t.Run("prefix", func(t *testing.T) { testFunc("prefix", t) })
t.Run("suffix", func(t *testing.T) { testFunc("suffix", t) })
t.Run("next-to-last", func(t *testing.T) { testFunc("next-to-last", t) })
t.Run("prefix", func(t *testing.T) { testFunc("v1/prefix", t) })
t.Run("suffix", func(t *testing.T) { testFunc("v1/suffix", t) })
t.Run("next-to-last", func(t *testing.T) { testFunc("v1/next-to-last", t) })
}
func TestPutBadValueType(t *testing.T) {
temp, cleanup := tempdir(t)
defer cleanup()
fs, err := flatfs.CreateOrOpen(temp, "prefix/2", false)
fs, err := flatfs.CreateOrOpen(temp, "v1/prefix/2", false)
if err != nil {
t.Fatalf("New fail: %v\n", err)
}
......@@ -454,7 +454,7 @@ func TestNoCluster(t *testing.T) {
tempdir, cleanup := tempdir(t)
defer cleanup()
fs, err := flatfs.CreateOrOpen(tempdir, "next-to-last/1", false)
fs, err := flatfs.CreateOrOpen(tempdir, "v1/next-to-last/1", false)
if err != nil {
t.Fatalf("New fail: %v\n", err)
}
......
......@@ -38,21 +38,20 @@ func ParseShardFunc(str string) (*ShardIdV1, error) {
}
str = trimmed
}
parts := strings.Split(str, "/")
if len(parts) == 3 {
version := parts[0]
if version != "v1" {
return nil, fmt.Errorf("expected 'v1' for version string got: %s\n", version)
}
parts = parts[1:]
}
if len(parts) != 2 {
if len(parts) != 3 {
return nil, fmt.Errorf("invalid shard identifier: %s", str)
}
id := &ShardIdV1{funName: parts[0]}
version := parts[0]
if version != "v1" {
return nil, fmt.Errorf("expected 'v1' for version string got: %s\n", version)
}
id := &ShardIdV1{funName: parts[1]}
param, err := strconv.Atoi(parts[1])
param, err := strconv.Atoi(parts[2])
if err != nil {
return nil, fmt.Errorf("invalid parameter: %v", err)
}
......
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