Unverified Commit 243fc729 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #82 from libp2p/test/metadata

test: add metadata test
parents e1511652 9a662b99
......@@ -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++ {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment