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