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
f50f59c1
Unverified
Commit
f50f59c1
authored
Mar 22, 2019
by
Michael Avila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more tests
parent
d3720199
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
10 deletions
+71
-10
mount/mount_test.go
mount/mount_test.go
+71
-10
No files found.
mount/mount_test.go
View file @
f50f59c1
...
...
@@ -502,17 +502,49 @@ func TestQueryFilterAcrossMountsWithSort(t *testing.T) {
}
}
func
TestQueryLimit
(
t
*
testing
.
T
)
{
func
TestQueryLimit
AndOffsetWithNoData
(
t
*
testing
.
T
)
{
mapds1
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
mapds2
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/rok"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/zoo"
),
Datastore
:
mapds2
},
})
m
.
Put
(
datastore
.
NewKey
(
"/rok/0"
),
[]
byte
(
"ghi"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/1"
),
[]
byte
(
"def"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/3"
),
[]
byte
(
"abc"
))
q
:=
query
.
Query
{
Limit
:
4
,
Offset
:
3
}
res
,
err
:=
m
.
Query
(
q
)
if
err
!=
nil
{
t
.
Fatalf
(
"Query fail: %v
\n
"
,
err
)
}
entries
,
err
:=
res
.
Rest
()
if
err
!=
nil
{
t
.
Fatalf
(
"Query Results.Rest fail: %v
\n
"
,
err
)
}
expect
:=
[]
string
{}
if
len
(
entries
)
!=
len
(
expect
)
{
t
.
Fatalf
(
"expected %d entries, but got %d"
,
len
(
expect
),
len
(
entries
))
}
err
=
res
.
Close
()
if
err
!=
nil
{
t
.
Errorf
(
"result.Close failed %d"
,
err
)
}
}
func
TestQueryLimitWithNotEnoughData
(
t
*
testing
.
T
)
{
mapds1
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
mapds2
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/rok"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/zoo"
),
Datastore
:
mapds2
},
})
m
.
Put
(
datastore
.
NewKey
(
"/zoo/0"
),
[]
byte
(
"123"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/1"
),
[]
byte
(
"167"
))
q
:=
query
.
Query
{
Limit
:
1
,
Orders
:
[]
query
.
Order
{
query
.
OrderByKeyDescending
{}}
}
q
:=
query
.
Query
{
Limit
:
4
}
res
,
err
:=
m
.
Query
(
q
)
if
err
!=
nil
{
t
.
Fatalf
(
"Query fail: %v
\n
"
,
err
)
...
...
@@ -524,17 +556,46 @@ func TestQueryLimit(t *testing.T) {
}
expect
:=
[]
string
{
"/rok/3"
,
"/zoo/0"
,
"/rok/1"
,
}
if
len
(
entries
)
!=
len
(
expect
)
{
t
.
Fatalf
(
"expected %d entries, but got %d"
,
len
(
expect
),
len
(
entries
))
}
for
i
,
e
:=
range
expect
{
if
e
!=
entries
[
i
]
.
Key
{
t
.
Errorf
(
"expected key %s, but got %s"
,
e
,
entries
[
i
]
.
Key
)
}
err
=
res
.
Close
()
if
err
!=
nil
{
t
.
Errorf
(
"result.Close failed %d"
,
err
)
}
}
func
TestQueryOffsetWithNotEnoughData
(
t
*
testing
.
T
)
{
mapds1
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
mapds2
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
m
:=
mount
.
New
([]
mount
.
Mount
{
{
Prefix
:
datastore
.
NewKey
(
"/rok"
),
Datastore
:
mapds1
},
{
Prefix
:
datastore
.
NewKey
(
"/zoo"
),
Datastore
:
mapds2
},
})
m
.
Put
(
datastore
.
NewKey
(
"/zoo/0"
),
[]
byte
(
"123"
))
m
.
Put
(
datastore
.
NewKey
(
"/rok/1"
),
[]
byte
(
"167"
))
q
:=
query
.
Query
{
Offset
:
4
}
res
,
err
:=
m
.
Query
(
q
)
if
err
!=
nil
{
t
.
Fatalf
(
"Query fail: %v
\n
"
,
err
)
}
entries
,
err
:=
res
.
Rest
()
if
err
!=
nil
{
t
.
Fatalf
(
"Query Results.Rest fail: %v
\n
"
,
err
)
}
expect
:=
[]
string
{}
if
len
(
entries
)
!=
len
(
expect
)
{
t
.
Fatalf
(
"expected %d entries, but got %d"
,
len
(
expect
),
len
(
entries
))
}
err
=
res
.
Close
()
...
...
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