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
p2p
go-p2p-peerstore
Commits
243fc729
Unverified
Commit
243fc729
authored
May 31, 2019
by
Steven Allen
Committed by
GitHub
May 31, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #82 from libp2p/test/metadata
test: add metadata test
parents
e1511652
9a662b99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
test/peerstore_suite.go
test/peerstore_suite.go
+41
-0
No files found.
test/peerstore_suite.go
View file @
243fc729
...
...
@@ -21,6 +21,7 @@ var peerstoreSuite = map[string]func(pstore.Peerstore) func(*testing.T){
"AddStreamDuplicates"
:
testAddrStreamDuplicates
,
"PeerstoreProtoStore"
:
testPeerstoreProtoStore
,
"BasicPeerstore"
:
testBasicPeerstore
,
"Metadata"
:
testMetadata
,
}
type
PeerstoreFactory
func
()
(
pstore
.
Peerstore
,
func
())
...
...
@@ -279,6 +280,46 @@ func testBasicPeerstore(ps pstore.Peerstore) func(t *testing.T) {
}
}
func
testMetadata
(
ps
pstore
.
Peerstore
)
func
(
t
*
testing
.
T
)
{
return
func
(
t
*
testing
.
T
)
{
pids
:=
make
([]
peer
.
ID
,
10
)
for
i
:=
range
pids
{
priv
,
_
,
_
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
512
)
p
,
_
:=
peer
.
IDFromPrivateKey
(
priv
)
pids
[
i
]
=
p
}
for
_
,
p
:=
range
pids
{
if
err
:=
ps
.
Put
(
p
,
"AgentVersion"
,
"string"
);
err
!=
nil
{
t
.
Errorf
(
"failed to put %q: %s"
,
"AgentVersion"
,
err
)
}
if
err
:=
ps
.
Put
(
p
,
"bar"
,
1
);
err
!=
nil
{
t
.
Errorf
(
"failed to put %q: %s"
,
"bar"
,
err
)
}
}
for
_
,
p
:=
range
pids
{
v
,
err
:=
ps
.
Get
(
p
,
"AgentVersion"
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to find %q: %s"
,
"AgentVersion"
,
err
)
continue
}
if
v
!=
"string"
{
t
.
Errorf
(
"expected %q, got %q"
,
"string"
,
p
)
continue
}
v
,
err
=
ps
.
Get
(
p
,
"bar"
)
if
err
!=
nil
{
t
.
Errorf
(
"failed to find %q: %s"
,
"bar"
,
err
)
continue
}
if
v
!=
1
{
t
.
Errorf
(
"expected %q, got %v"
,
1
,
v
)
continue
}
}
}
}
func
getAddrs
(
t
*
testing
.
T
,
n
int
)
[]
ma
.
Multiaddr
{
var
addrs
[]
ma
.
Multiaddr
for
i
:=
0
;
i
<
n
;
i
++
{
...
...
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