Commit 3067a8a0 authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(peer): create peer through peerstore

for safety!

use mockpeer.WithID methods to create peers in tests

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent f6c0f472
......@@ -14,6 +14,7 @@ import (
mux "github.com/jbenet/go-ipfs/net/mux"
netservice "github.com/jbenet/go-ipfs/net/service"
peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/peer/mock"
u "github.com/jbenet/go-ipfs/util"
"fmt"
......@@ -68,7 +69,7 @@ func makePeer(addr ma.Multiaddr) peer.Peer {
if err != nil {
panic(err)
}
p, err := peer.WithKeyPair(sk, pk)
p, err := mockpeer.WithKeyPair(sk, pk)
if err != nil {
panic(err)
}
......
......@@ -12,6 +12,7 @@ import (
msg "github.com/jbenet/go-ipfs/net/message"
mux "github.com/jbenet/go-ipfs/net/mux"
peer "github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/peer/mock"
"github.com/jbenet/go-ipfs/routing"
pb "github.com/jbenet/go-ipfs/routing/dht/pb"
u "github.com/jbenet/go-ipfs/util"
......@@ -210,7 +211,7 @@ func TestGetFailures(t *testing.T) {
func _randPeer() peer.Peer {
id := make(peer.ID, 16)
crand.Read(id)
p := peer.WithID(id)
p := mockpeer.WithID(id)
return p
}
......
......@@ -4,6 +4,7 @@ import (
"testing"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/peer/mock"
u "github.com/jbenet/go-ipfs/util"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
......@@ -14,7 +15,7 @@ func TestProviderManager(t *testing.T) {
mid := peer.ID("testing")
p := NewProviderManager(ctx, mid)
a := u.Key("test")
p.AddProvider(a, peer.WithIDString("testingprovider"))
p.AddProvider(a, mockpeer.WithIDString("testingprovider"))
resp := p.GetProviders(ctx, a)
if len(resp) != 1 {
t.Fatal("Could not retrieve provider.")
......
......@@ -6,6 +6,7 @@ import (
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
"github.com/jbenet/go-ipfs/peer"
"github.com/jbenet/go-ipfs/peer/mock"
u "github.com/jbenet/go-ipfs/util"
)
......@@ -20,7 +21,7 @@ func TestKeyNotFound(t *testing.T) {
func TestSetAndGet(t *testing.T) {
pid := peer.ID([]byte("the peer id"))
p := peer.WithID(pid)
p := mockpeer.WithID(pid)
k := u.Key("42")
rs := VirtualRoutingServer()
err := rs.Announce(p, k)
......@@ -40,7 +41,7 @@ func TestSetAndGet(t *testing.T) {
}
func TestClientFindProviders(t *testing.T) {
peer := peer.WithIDString("42")
peer := mockpeer.WithIDString("42")
rs := VirtualRoutingServer()
client := rs.Client(peer)
......@@ -79,7 +80,7 @@ func TestClientOverMax(t *testing.T) {
k := u.Key("hello")
numProvidersForHelloKey := 100
for i := 0; i < numProvidersForHelloKey; i++ {
peer := peer.WithIDString(string(i))
peer := mockpeer.WithIDString(string(i))
err := rs.Announce(peer, k)
if err != nil {
t.Fatal(err)
......@@ -92,7 +93,7 @@ func TestClientOverMax(t *testing.T) {
}
max := 10
peer := peer.WithIDString("TODO")
peer := mockpeer.WithIDString("TODO")
client := rs.Client(peer)
providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
......@@ -114,7 +115,7 @@ func TestCanceledContext(t *testing.T) {
i := 0
go func() { // infinite stream
for {
peer := peer.WithIDString(string(i))
peer := mockpeer.WithIDString(string(i))
err := rs.Announce(peer, k)
if err != nil {
t.Fatal(err)
......@@ -123,7 +124,7 @@ func TestCanceledContext(t *testing.T) {
}
}()
local := peer.WithIDString("peer id doesn't matter")
local := mockpeer.WithIDString("peer id doesn't matter")
client := rs.Client(local)
t.Log("warning: max is finite so this test is non-deterministic")
......
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