Commit 776fe95d authored by Brian Tiger Chow's avatar Brian Tiger Chow

fix(core, peer) helpers to testutil, err handling

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