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-dms3-provider
Commits
96406fe0
Commit
96406fe0
authored
Mar 16, 2019
by
Erik Ingenito
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Additional provider tests
License: MIT Signed-off-by:
Erik Ingenito
<
erik@carbonfive.com
>
parent
74884fbe
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
11 deletions
+61
-11
provider_test.go
provider_test.go
+9
-10
queue_test.go
queue_test.go
+52
-1
No files found.
provider_test.go
View file @
96406fe0
...
...
@@ -19,6 +19,15 @@ type mockRouting struct {
provided
chan
cid
.
Cid
}
func
(
r
*
mockRouting
)
Provide
(
ctx
context
.
Context
,
cid
cid
.
Cid
,
recursive
bool
)
error
{
r
.
provided
<-
cid
return
nil
}
func
(
r
*
mockRouting
)
FindProvidersAsync
(
ctx
context
.
Context
,
cid
cid
.
Cid
,
timeout
int
)
<-
chan
pstore
.
PeerInfo
{
return
nil
}
func
mockContentRouting
()
*
mockRouting
{
r
:=
mockRouting
{}
r
.
provided
=
make
(
chan
cid
.
Cid
)
...
...
@@ -68,13 +77,3 @@ func TestAnnouncement(t *testing.T) {
}
}
}
func
(
r
*
mockRouting
)
Provide
(
ctx
context
.
Context
,
cid
cid
.
Cid
,
recursive
bool
)
error
{
r
.
provided
<-
cid
return
nil
}
// Search for peers who are able to provide a given key
func
(
r
*
mockRouting
)
FindProvidersAsync
(
ctx
context
.
Context
,
cid
cid
.
Cid
,
timeout
int
)
<-
chan
pstore
.
PeerInfo
{
return
nil
}
queue_test.go
View file @
96406fe0
...
...
@@ -52,7 +52,37 @@ func TestBasicOperation(t *testing.T) {
assertOrdered
(
cids
,
queue
,
t
)
}
func
TestInitialization
(
t
*
testing
.
T
)
{
func
TestSparseDatastore
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
defer
ctx
.
Done
()
ds
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
queue
,
err
:=
NewQueue
(
ctx
,
"test"
,
ds
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cids
:=
makeCids
(
10
)
for
_
,
c
:=
range
cids
{
queue
.
Enqueue
(
c
)
}
// remove entries in the middle
err
=
queue
.
ds
.
Delete
(
queue
.
queueKey
(
5
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
queue
.
ds
.
Delete
(
queue
.
queueKey
(
6
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
expected
:=
append
(
cids
[
:
5
],
cids
[
7
:
]
...
)
assertOrdered
(
expected
,
queue
,
t
)
}
func
TestMangledData
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
defer
ctx
.
Done
()
...
...
@@ -63,7 +93,28 @@ func TestInitialization(t *testing.T) {
}
cids
:=
makeCids
(
10
)
for
_
,
c
:=
range
cids
{
queue
.
Enqueue
(
c
)
}
// remove entries in the middle
err
=
queue
.
ds
.
Put
(
queue
.
queueKey
(
5
),
[]
byte
(
"borked"
))
expected
:=
append
(
cids
[
:
5
],
cids
[
6
:
]
...
)
assertOrdered
(
expected
,
queue
,
t
)
}
func
TestInitialization
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
defer
ctx
.
Done
()
ds
:=
sync
.
MutexWrap
(
datastore
.
NewMapDatastore
())
queue
,
err
:=
NewQueue
(
ctx
,
"test"
,
ds
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cids
:=
makeCids
(
10
)
for
_
,
c
:=
range
cids
{
queue
.
Enqueue
(
c
)
}
...
...
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