Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-flatfs
Commits
fbc4d441
Commit
fbc4d441
authored
Jan 11, 2017
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test that the correct prefix is used in shard identifier.
parent
b02d206e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
flatfs_test.go
flatfs_test.go
+10
-0
shard.go
shard.go
+11
-5
No files found.
flatfs_test.go
View file @
fbc4d441
...
...
@@ -440,6 +440,16 @@ func TestSHARDINGFile(t *testing.T) {
}
}
func TestInvalidPrefix(t *testing.T) {
tempdir, cleanup := tempdir(t)
defer cleanup()
err := flatfs.Create(tempdir, "/bad/prefix/v1/next-to-last/2")
if err == nil {
t.Fatalf("Expected an error when creating a datastore with a bad prefix for the sharding function")
}
}
func TestNoCluster(t *testing.T) {
tempdir, cleanup := tempdir(t)
defer cleanup()
...
...
shard.go
View file @
fbc4d441
...
...
@@ -15,10 +15,10 @@ type ShardIdV1 struct {
fun
ShardFunc
}
const
PREFIX
=
"/repo/flatfs/shard"
const
PREFIX
=
"/repo/flatfs/shard
/
"
func
(
f
*
ShardIdV1
)
String
()
string
{
return
fmt
.
Sprintf
(
"%s
/
v1/%s/%d"
,
PREFIX
,
f
.
funName
,
f
.
param
)
return
fmt
.
Sprintf
(
"%sv1/%s/%d"
,
PREFIX
,
f
.
funName
,
f
.
param
)
}
func
(
f
*
ShardIdV1
)
Func
()
ShardFunc
{
...
...
@@ -27,11 +27,17 @@ func (f *ShardIdV1) Func() ShardFunc {
func
ParseShardFunc
(
str
string
)
(
*
ShardIdV1
,
error
)
{
str
=
strings
.
TrimSpace
(
str
)
parts
:=
strings
.
Split
(
str
,
"/"
)
// ignore prefix for now
if
len
(
parts
)
>
3
{
parts
=
parts
[
len
(
parts
)
-
3
:
]
if
len
(
str
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"empty shard identifier"
)
}
if
str
[
0
]
==
'/'
{
if
!
strings
.
HasPrefix
(
str
,
PREFIX
)
{
return
nil
,
fmt
.
Errorf
(
"invalid prefix in shard identifier: %s"
,
str
)
}
str
=
str
[
len
(
PREFIX
)
:
]
}
parts
:=
strings
.
Split
(
str
,
"/"
)
if
len
(
parts
)
==
3
{
version
:=
parts
[
0
]
if
version
!=
"v1"
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment