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-datastore
Commits
f2327ba5
Commit
f2327ba5
authored
Feb 10, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(suite): add a bunch of prefix tests for the new behavior
parent
83f9a950
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
63 additions
and
10 deletions
+63
-10
go.sum
go.sum
+1
-0
mount/mount_test.go
mount/mount_test.go
+3
-3
test/basic_tests.go
test/basic_tests.go
+58
-7
test/suite.go
test/suite.go
+1
-0
No files found.
go.sum
View file @
f2327ba5
...
@@ -6,6 +6,7 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5f
...
@@ -6,6 +6,7 @@ github.com/jbenet/goprocess v0.0.0-20160826012719-b497e2f366b8 h1:bspPhN+oKYFk5f
github.com/jbenet/goprocess
v0.0.0-20160826012719-b497e2f366b8/go.mod h1:
Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
github.com/jbenet/goprocess
v0.0.0-20160826012719-b497e2f366b8/go.mod h1:
Ly/wlsjFq/qrU3Rar62tu1gASgGw6chQbSh/XgIIXCY=
github.com/kr/pretty
v0.1.0 h1:
L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty
v0.1.0 h1:
L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty
v0.1.0/go.mod h1:
dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty
v0.1.0/go.mod h1:
dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty
v1.1.1 h1:
VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/kr/pty
v1.1.1/go.mod h1:
pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty
v1.1.1/go.mod h1:
pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text
v0.1.0 h1:
45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text
v0.1.0 h1:
45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text
v0.1.0/go.mod h1:
4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text
v0.1.0/go.mod h1:
4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
...
...
mount/mount_test.go
View file @
f2327ba5
...
@@ -841,9 +841,9 @@ func TestSuite(t *testing.T) {
...
@@ -841,9 +841,9 @@ func TestSuite(t *testing.T) {
mapds2
:=
datastore
.
NewMapDatastore
()
mapds2
:=
datastore
.
NewMapDatastore
()
mapds3
:=
datastore
.
NewMapDatastore
()
mapds3
:=
datastore
.
NewMapDatastore
()
m
:=
mount
.
New
([]
mount
.
Mount
{
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/
foo
"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/
prefix
"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/
bar
"
),
Datastore
:
mapds2
},
{
Prefix
:
datastore
.
NewKey
(
"/
prefix/sub
"
),
Datastore
:
mapds2
},
{
Prefix
:
datastore
.
NewKey
(
"/
baz
"
),
Datastore
:
mapds3
},
{
Prefix
:
datastore
.
NewKey
(
"/
0
"
),
Datastore
:
mapds3
},
{
Prefix
:
datastore
.
NewKey
(
"/"
),
Datastore
:
mapds0
},
{
Prefix
:
datastore
.
NewKey
(
"/"
),
Datastore
:
mapds0
},
})
})
dstest
.
SubtestAll
(
t
,
m
)
dstest
.
SubtestAll
(
t
,
m
)
...
...
test/basic_tests.go
View file @
f2327ba5
...
@@ -177,27 +177,27 @@ func SubtestManyKeysAndQuery(t *testing.T, ds dstore.Datastore) {
...
@@ -177,27 +177,27 @@ func SubtestManyKeysAndQuery(t *testing.T, ds dstore.Datastore) {
}
}
func
SubtestBasicSync
(
t
*
testing
.
T
,
ds
dstore
.
Datastore
)
{
func
SubtestBasicSync
(
t
*
testing
.
T
,
ds
dstore
.
Datastore
)
{
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"
foo
"
));
err
!=
nil
{
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"
prefix
"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
err
:=
ds
.
Put
(
dstore
.
NewKey
(
"/
foo
"
),
[]
byte
(
"foo"
));
err
!=
nil
{
if
err
:=
ds
.
Put
(
dstore
.
NewKey
(
"/
prefix
"
),
[]
byte
(
"foo"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
foo
"
));
err
!=
nil
{
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
prefix
"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
err
:=
ds
.
Put
(
dstore
.
NewKey
(
"/
foo/bar
"
),
[]
byte
(
"bar"
));
err
!=
nil
{
if
err
:=
ds
.
Put
(
dstore
.
NewKey
(
"/
prefix/sub
"
),
[]
byte
(
"bar"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
foo
"
));
err
!=
nil
{
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
prefix
"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
foo/bar
"
));
err
!=
nil
{
if
err
:=
ds
.
Sync
(
dstore
.
NewKey
(
"/
prefix/sub
"
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
@@ -237,6 +237,11 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
...
@@ -237,6 +237,11 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
Key
:
"/2"
,
Key
:
"/2"
,
}},
}},
}
}
prefixes
:=
[]
string
{
""
,
"/prefix"
,
"/0"
,
// keys exist under this prefix but they shouldn't match.
}
orders
:=
[][]
dsq
.
Order
{
orders
:=
[][]
dsq
.
Order
{
{
dsq
.
OrderByKey
{}},
{
dsq
.
OrderByKey
{}},
{
dsq
.
OrderByKeyDescending
{}},
{
dsq
.
OrderByKeyDescending
{}},
...
@@ -255,8 +260,9 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
...
@@ -255,8 +260,9 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
Limit
:
limits
[
perm
[
1
]],
Limit
:
limits
[
perm
[
1
]],
Filters
:
filters
[
perm
[
2
]],
Filters
:
filters
[
perm
[
2
]],
Orders
:
orders
[
perm
[
3
]],
Orders
:
orders
[
perm
[
3
]],
Prefix
:
prefixes
[
perm
[
4
]],
}
}
length
:=
lengths
[
perm
[
4
]]
length
:=
lengths
[
perm
[
5
]]
t
.
Run
(
strings
.
ReplaceAll
(
fmt
.
Sprintf
(
"%d/{%s}"
,
length
,
q
),
" "
,
"·"
),
func
(
t
*
testing
.
T
)
{
t
.
Run
(
strings
.
ReplaceAll
(
fmt
.
Sprintf
(
"%d/{%s}"
,
length
,
q
),
" "
,
"·"
),
func
(
t
*
testing
.
T
)
{
subtestQuery
(
t
,
ds
,
q
,
length
)
subtestQuery
(
t
,
ds
,
q
,
length
)
...
@@ -266,6 +272,7 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
...
@@ -266,6 +272,7 @@ func SubtestCombinations(t *testing.T, ds dstore.Datastore) {
len
(
limits
),
len
(
limits
),
len
(
filters
),
len
(
filters
),
len
(
orders
),
len
(
orders
),
len
(
prefixes
),
len
(
lengths
),
len
(
lengths
),
)
)
}
}
...
@@ -335,6 +342,28 @@ func SubtestReturnSizes(t *testing.T, ds dstore.Datastore) {
...
@@ -335,6 +342,28 @@ func SubtestReturnSizes(t *testing.T, ds dstore.Datastore) {
subtestQuery
(
t
,
ds
,
dsq
.
Query
{
ReturnsSizes
:
true
},
100
)
subtestQuery
(
t
,
ds
,
dsq
.
Query
{
ReturnsSizes
:
true
},
100
)
}
}
func
SubtestPrefix
(
t
*
testing
.
T
,
ds
dstore
.
Datastore
)
{
test
:=
func
(
prefix
string
)
{
t
.
Run
(
prefix
,
func
(
t
*
testing
.
T
)
{
subtestQuery
(
t
,
ds
,
dsq
.
Query
{
Prefix
:
prefix
,
},
100
)
})
}
test
(
""
)
test
(
"/"
)
test
(
"/./"
)
test
(
"/.././/"
)
test
(
"/prefix/../"
)
test
(
"/prefix"
)
test
(
"/prefix/"
)
test
(
"/prefix/sub/"
)
test
(
"/0/"
)
test
(
"/bad/"
)
}
func
randValue
()
[]
byte
{
func
randValue
()
[]
byte
{
value
:=
make
([]
byte
,
64
)
value
:=
make
([]
byte
,
64
)
rand
.
Read
(
value
)
rand
.
Read
(
value
)
...
@@ -354,6 +383,28 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
...
@@ -354,6 +383,28 @@ func subtestQuery(t *testing.T, ds dstore.Datastore, q dsq.Query, count int) {
})
})
}
}
for
i
:=
0
;
i
<
count
;
i
++
{
s
:=
fmt
.
Sprintf
(
"/prefix/%dkey%d"
,
i
,
i
)
key
:=
dstore
.
NewKey
(
s
)
.
String
()
value
:=
randValue
()
input
=
append
(
input
,
dsq
.
Entry
{
Key
:
key
,
Size
:
len
(
value
),
Value
:
value
,
})
}
for
i
:=
0
;
i
<
count
;
i
++
{
s
:=
fmt
.
Sprintf
(
"/prefix/sub/%dkey%d"
,
i
,
i
)
key
:=
dstore
.
NewKey
(
s
)
.
String
()
value
:=
randValue
()
input
=
append
(
input
,
dsq
.
Entry
{
Key
:
key
,
Size
:
len
(
value
),
Value
:
value
,
})
}
t
.
Logf
(
"putting %d values"
,
count
)
t
.
Logf
(
"putting %d values"
,
count
)
for
i
,
e
:=
range
input
{
for
i
,
e
:=
range
input
{
err
:=
ds
.
Put
(
dstore
.
RawKey
(
e
.
Key
),
e
.
Value
)
err
:=
ds
.
Put
(
dstore
.
RawKey
(
e
.
Key
),
e
.
Value
)
...
...
test/suite.go
View file @
f2327ba5
...
@@ -14,6 +14,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
...
@@ -14,6 +14,7 @@ var BasicSubtests = []func(t *testing.T, ds dstore.Datastore){
SubtestBasicPutGet
,
SubtestBasicPutGet
,
SubtestNotFounds
,
SubtestNotFounds
,
SubtestCombinations
,
SubtestCombinations
,
SubtestPrefix
,
SubtestOrder
,
SubtestOrder
,
SubtestLimit
,
SubtestLimit
,
SubtestFilter
,
SubtestFilter
,
...
...
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