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
2fe8b68a
Commit
2fe8b68a
authored
Feb 10, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test(query): be thurough
parent
ae428d8d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
query/filter_test.go
query/filter_test.go
+7
-0
query/order_test.go
query/order_test.go
+6
-0
query/query_test.go
query/query_test.go
+20
-3
No files found.
query/filter_test.go
View file @
2fe8b68a
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
)
)
func
testKeyFilter
(
t
*
testing
.
T
,
f
Filter
,
keys
[]
string
,
expect
[]
string
)
{
func
testKeyFilter
(
t
*
testing
.
T
,
f
Filter
,
keys
[]
string
,
expect
[]
string
)
{
t
.
Helper
()
e
:=
make
([]
Entry
,
len
(
keys
))
e
:=
make
([]
Entry
,
len
(
keys
))
for
i
,
k
:=
range
keys
{
for
i
,
k
:=
range
keys
{
e
[
i
]
=
Entry
{
Key
:
k
}
e
[
i
]
=
Entry
{
Key
:
k
}
...
@@ -37,6 +38,8 @@ func TestFilterKeyCompare(t *testing.T) {
...
@@ -37,6 +38,8 @@ func TestFilterKeyCompare(t *testing.T) {
testKeyFilter
(
t
,
FilterKeyCompare
{
GreaterThan
,
"/ab"
},
sampleKeys
,
[]
string
{
testKeyFilter
(
t
,
FilterKeyCompare
{
GreaterThan
,
"/ab"
},
sampleKeys
,
[]
string
{
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
})
})
...
@@ -51,6 +54,8 @@ func TestFilterKeyPrefix(t *testing.T) {
...
@@ -51,6 +54,8 @@ func TestFilterKeyPrefix(t *testing.T) {
testKeyFilter
(
t
,
FilterKeyPrefix
{
"/a"
},
sampleKeys
,
[]
string
{
testKeyFilter
(
t
,
FilterKeyPrefix
{
"/a"
},
sampleKeys
,
[]
string
{
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
@@ -59,5 +64,7 @@ func TestFilterKeyPrefix(t *testing.T) {
...
@@ -59,5 +64,7 @@ func TestFilterKeyPrefix(t *testing.T) {
testKeyFilter
(
t
,
FilterKeyPrefix
{
"/ab/"
},
sampleKeys
,
[]
string
{
testKeyFilter
(
t
,
FilterKeyPrefix
{
"/ab/"
},
sampleKeys
,
[]
string
{
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
})
})
}
}
query/order_test.go
View file @
2fe8b68a
...
@@ -6,6 +6,8 @@ import (
...
@@ -6,6 +6,8 @@ import (
)
)
func
testKeyOrder
(
t
*
testing
.
T
,
f
Order
,
keys
[]
string
,
expect
[]
string
)
{
func
testKeyOrder
(
t
*
testing
.
T
,
f
Order
,
keys
[]
string
,
expect
[]
string
)
{
t
.
Helper
()
e
:=
make
([]
Entry
,
len
(
keys
))
e
:=
make
([]
Entry
,
len
(
keys
))
for
i
,
k
:=
range
keys
{
for
i
,
k
:=
range
keys
{
e
[
i
]
=
Entry
{
Key
:
k
}
e
[
i
]
=
Entry
{
Key
:
k
}
...
@@ -39,12 +41,16 @@ func TestOrderByKey(t *testing.T) {
...
@@ -39,12 +41,16 @@ func TestOrderByKey(t *testing.T) {
"/ab"
,
"/ab"
,
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
})
})
testKeyOrder
(
t
,
OrderByKeyDescending
{},
sampleKeys
,
[]
string
{
testKeyOrder
(
t
,
OrderByKeyDescending
{},
sampleKeys
,
[]
string
{
"/abcf"
,
"/abcf"
,
"/abce"
,
"/abce"
,
"/ab/fg"
,
"/ab/ef"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/c"
,
"/ab/c"
,
"/ab"
,
"/ab"
,
...
...
query/query_test.go
View file @
2fe8b68a
...
@@ -9,6 +9,8 @@ import (
...
@@ -9,6 +9,8 @@ import (
var
sampleKeys
=
[]
string
{
var
sampleKeys
=
[]
string
{
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
@@ -60,8 +62,8 @@ func TestNaiveQueryApply(t *testing.T) {
...
@@ -60,8 +62,8 @@ func TestNaiveQueryApply(t *testing.T) {
q
=
Query
{
Offset
:
3
,
Limit
:
2
}
q
=
Query
{
Offset
:
3
,
Limit
:
2
}
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
"/ab
ce
"
,
"/ab
/fg
"
,
"/a
bcf
"
,
"/a"
,
})
})
f
:=
&
FilterKeyCompare
{
Op
:
Equal
,
Key
:
"/ab"
}
f
:=
&
FilterKeyCompare
{
Op
:
Equal
,
Key
:
"/ab"
}
...
@@ -74,12 +76,16 @@ func TestNaiveQueryApply(t *testing.T) {
...
@@ -74,12 +76,16 @@ func TestNaiveQueryApply(t *testing.T) {
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
})
})
q
=
Query
{
Orders
:
[]
Order
{
OrderByKeyDescending
{}}}
q
=
Query
{
Orders
:
[]
Order
{
OrderByKeyDescending
{}}}
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
"/abcf"
,
"/abcf"
,
"/abce"
,
"/abce"
,
"/ab/fg"
,
"/ab/ef"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/c"
,
"/ab/c"
,
"/ab"
,
"/ab"
,
...
@@ -87,18 +93,20 @@ func TestNaiveQueryApply(t *testing.T) {
...
@@ -87,18 +93,20 @@ func TestNaiveQueryApply(t *testing.T) {
})
})
q
=
Query
{
q
=
Query
{
Limit
:
3
,
Limit
:
2
,
Offset
:
1
,
Offset
:
1
,
Prefix
:
"/ab"
,
Prefix
:
"/ab"
,
Orders
:
[]
Order
{
OrderByKey
{}},
Orders
:
[]
Order
{
OrderByKey
{}},
}
}
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
testNaiveQueryApply
(
t
,
q
,
sampleKeys
,
[]
string
{
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
})
})
}
}
func
TestLimit
(
t
*
testing
.
T
)
{
func
TestLimit
(
t
*
testing
.
T
)
{
testKeyLimit
:=
func
(
t
*
testing
.
T
,
limit
int
,
keys
[]
string
,
expect
[]
string
)
{
testKeyLimit
:=
func
(
t
*
testing
.
T
,
limit
int
,
keys
[]
string
,
expect
[]
string
)
{
t
.
Helper
()
e
:=
make
([]
Entry
,
len
(
keys
))
e
:=
make
([]
Entry
,
len
(
keys
))
for
i
,
k
:=
range
keys
{
for
i
,
k
:=
range
keys
{
e
[
i
]
=
Entry
{
Key
:
k
}
e
[
i
]
=
Entry
{
Key
:
k
}
...
@@ -112,6 +120,8 @@ func TestLimit(t *testing.T) {
...
@@ -112,6 +120,8 @@ func TestLimit(t *testing.T) {
testKeyLimit
(
t
,
0
,
sampleKeys
,
[]
string
{
// none
testKeyLimit
(
t
,
0
,
sampleKeys
,
[]
string
{
// none
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
@@ -121,6 +131,8 @@ func TestLimit(t *testing.T) {
...
@@ -121,6 +131,8 @@ func TestLimit(t *testing.T) {
testKeyLimit
(
t
,
10
,
sampleKeys
,
[]
string
{
// large
testKeyLimit
(
t
,
10
,
sampleKeys
,
[]
string
{
// large
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
@@ -136,6 +148,7 @@ func TestLimit(t *testing.T) {
...
@@ -136,6 +148,7 @@ func TestLimit(t *testing.T) {
func
TestOffset
(
t
*
testing
.
T
)
{
func
TestOffset
(
t
*
testing
.
T
)
{
testOffset
:=
func
(
t
*
testing
.
T
,
offset
int
,
keys
[]
string
,
expect
[]
string
)
{
testOffset
:=
func
(
t
*
testing
.
T
,
offset
int
,
keys
[]
string
,
expect
[]
string
)
{
t
.
Helper
()
e
:=
make
([]
Entry
,
len
(
keys
))
e
:=
make
([]
Entry
,
len
(
keys
))
for
i
,
k
:=
range
keys
{
for
i
,
k
:=
range
keys
{
e
[
i
]
=
Entry
{
Key
:
k
}
e
[
i
]
=
Entry
{
Key
:
k
}
...
@@ -149,6 +162,8 @@ func TestOffset(t *testing.T) {
...
@@ -149,6 +162,8 @@ func TestOffset(t *testing.T) {
testOffset
(
t
,
0
,
sampleKeys
,
[]
string
{
// none
testOffset
(
t
,
0
,
sampleKeys
,
[]
string
{
// none
"/ab/c"
,
"/ab/c"
,
"/ab/cd"
,
"/ab/cd"
,
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
@@ -159,6 +174,8 @@ func TestOffset(t *testing.T) {
...
@@ -159,6 +174,8 @@ func TestOffset(t *testing.T) {
})
})
testOffset
(
t
,
2
,
sampleKeys
,
[]
string
{
testOffset
(
t
,
2
,
sampleKeys
,
[]
string
{
"/ab/ef"
,
"/ab/fg"
,
"/a"
,
"/a"
,
"/abce"
,
"/abce"
,
"/abcf"
,
"/abcf"
,
...
...
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