mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +08:00
fix(core, peer) helpers to testutil, err handling
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:
@ -267,7 +267,8 @@ func initConnections(ctx context.Context, cfg *config.Config, pstore peer.Peerst
|
|||||||
// setup peer
|
// setup peer
|
||||||
id, err := peer.DecodePrettyID(p.PeerID)
|
id, err := peer.DecodePrettyID(p.PeerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// return err
|
log.Criticalf("Bootstrapping error: %v", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
npeer, err := pstore.FindOrCreate(id)
|
npeer, err := pstore.FindOrCreate(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,9 +7,9 @@ import (
|
|||||||
|
|
||||||
ci "github.com/jbenet/go-ipfs/crypto"
|
ci "github.com/jbenet/go-ipfs/crypto"
|
||||||
"github.com/jbenet/go-ipfs/peer"
|
"github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
|
||||||
"github.com/jbenet/go-ipfs/util"
|
"github.com/jbenet/go-ipfs/util"
|
||||||
"github.com/jbenet/go-ipfs/util/pipes"
|
"github.com/jbenet/go-ipfs/util/pipes"
|
||||||
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getPeer(tb testing.TB) peer.Peer {
|
func getPeer(tb testing.TB) peer.Peer {
|
||||||
@ -18,7 +18,7 @@ func getPeer(tb testing.TB) peer.Peer {
|
|||||||
tb.Fatal(err)
|
tb.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := mockpeer.WithKeyPair(privk, pubk)
|
p, err := testutil.NewPeerWithKeyPair(privk, pubk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tb.Fatal(err)
|
tb.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import (
|
|||||||
blocks "github.com/jbenet/go-ipfs/blocks"
|
blocks "github.com/jbenet/go-ipfs/blocks"
|
||||||
blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
|
blocksutil "github.com/jbenet/go-ipfs/blocks/blocksutil"
|
||||||
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
|
tn "github.com/jbenet/go-ipfs/exchange/bitswap/testnet"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
|
||||||
mock "github.com/jbenet/go-ipfs/routing/mock"
|
mock "github.com/jbenet/go-ipfs/routing/mock"
|
||||||
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestClose(t *testing.T) {
|
func TestClose(t *testing.T) {
|
||||||
@ -53,7 +53,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) {
|
|||||||
g := NewSessionGenerator(net, rs)
|
g := NewSessionGenerator(net, rs)
|
||||||
|
|
||||||
block := blocks.NewBlock([]byte("block"))
|
block := blocks.NewBlock([]byte("block"))
|
||||||
rs.Announce(mockpeer.WithIDString("testing"), block.Key()) // but not on network
|
rs.Announce(testutil.NewPeerWithIDString("testing"), block.Key()) // but not on network
|
||||||
|
|
||||||
solo := g.Next()
|
solo := g.Next()
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ import (
|
|||||||
|
|
||||||
blocks "github.com/jbenet/go-ipfs/blocks"
|
blocks "github.com/jbenet/go-ipfs/blocks"
|
||||||
pb "github.com/jbenet/go-ipfs/exchange/bitswap/message/internal/pb"
|
pb "github.com/jbenet/go-ipfs/exchange/bitswap/message/internal/pb"
|
||||||
"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 TestAppendWanted(t *testing.T) {
|
func TestAppendWanted(t *testing.T) {
|
||||||
@ -89,7 +89,7 @@ func TestCopyProtoByValue(t *testing.T) {
|
|||||||
|
|
||||||
func TestToNetMethodSetsPeer(t *testing.T) {
|
func TestToNetMethodSetsPeer(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
p := mockpeer.WithIDString("X")
|
p := testutil.NewPeerWithIDString("X")
|
||||||
netmsg, err := m.ToNet(p)
|
netmsg, err := m.ToNet(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -107,7 +107,7 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
|
|||||||
original.AddWanted(u.Key("T"))
|
original.AddWanted(u.Key("T"))
|
||||||
original.AddWanted(u.Key("F"))
|
original.AddWanted(u.Key("F"))
|
||||||
|
|
||||||
p := mockpeer.WithIDString("X")
|
p := testutil.NewPeerWithIDString("X")
|
||||||
netmsg, err := original.ToNet(p)
|
netmsg, err := original.ToNet(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -138,7 +138,7 @@ func TestToAndFromNetMessage(t *testing.T) {
|
|||||||
original.AddBlock(blocks.NewBlock([]byte("F")))
|
original.AddBlock(blocks.NewBlock([]byte("F")))
|
||||||
original.AddBlock(blocks.NewBlock([]byte("M")))
|
original.AddBlock(blocks.NewBlock([]byte("M")))
|
||||||
|
|
||||||
p := mockpeer.WithIDString("X")
|
p := testutil.NewPeerWithIDString("X")
|
||||||
netmsg, err := original.ToNet(p)
|
netmsg, err := original.ToNet(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
blocks "github.com/jbenet/go-ipfs/blocks"
|
blocks "github.com/jbenet/go-ipfs/blocks"
|
||||||
message "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
message "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type peerAndStrategist struct {
|
type peerAndStrategist struct {
|
||||||
@ -17,7 +17,7 @@ type peerAndStrategist struct {
|
|||||||
|
|
||||||
func newPeerAndStrategist(idStr string) peerAndStrategist {
|
func newPeerAndStrategist(idStr string) peerAndStrategist {
|
||||||
return peerAndStrategist{
|
return peerAndStrategist{
|
||||||
Peer: mockpeer.WithIDString(idStr),
|
Peer: testutil.NewPeerWithIDString(idStr),
|
||||||
Strategy: New(true),
|
Strategy: New(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
bsmsg "github.com/jbenet/go-ipfs/exchange/bitswap/message"
|
||||||
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
|
bsnet "github.com/jbenet/go-ipfs/exchange/bitswap/network"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSendRequestToCooperativePeer(t *testing.T) {
|
func TestSendRequestToCooperativePeer(t *testing.T) {
|
||||||
@ -19,8 +19,8 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
|
|||||||
|
|
||||||
t.Log("Get two network adapters")
|
t.Log("Get two network adapters")
|
||||||
|
|
||||||
initiator := net.Adapter(mockpeer.WithIDString("initiator"))
|
initiator := net.Adapter(testutil.NewPeerWithIDString("initiator"))
|
||||||
recipient := net.Adapter(mockpeer.WithID(idOfRecipient))
|
recipient := net.Adapter(testutil.NewPeerWithID(idOfRecipient))
|
||||||
|
|
||||||
expectedStr := "response from recipient"
|
expectedStr := "response from recipient"
|
||||||
recipient.SetDelegate(lambda(func(
|
recipient.SetDelegate(lambda(func(
|
||||||
@ -44,7 +44,7 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
|
|||||||
message := bsmsg.New()
|
message := bsmsg.New()
|
||||||
message.AddBlock(blocks.NewBlock([]byte("data")))
|
message.AddBlock(blocks.NewBlock([]byte("data")))
|
||||||
response, err := initiator.SendRequest(
|
response, err := initiator.SendRequest(
|
||||||
context.Background(), mockpeer.WithID(idOfRecipient), message)
|
context.Background(), testutil.NewPeerWithID(idOfRecipient), message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -62,8 +62,8 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
|
|||||||
func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
|
func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
|
||||||
net := VirtualNetwork()
|
net := VirtualNetwork()
|
||||||
idOfResponder := []byte("responder")
|
idOfResponder := []byte("responder")
|
||||||
waiter := net.Adapter(mockpeer.WithIDString("waiter"))
|
waiter := net.Adapter(testutil.NewPeerWithIDString("waiter"))
|
||||||
responder := net.Adapter(mockpeer.WithID(idOfResponder))
|
responder := net.Adapter(testutil.NewPeerWithID(idOfResponder))
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
@ -108,7 +108,7 @@ func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
|
|||||||
messageSentAsync := bsmsg.New()
|
messageSentAsync := bsmsg.New()
|
||||||
messageSentAsync.AddBlock(blocks.NewBlock([]byte("data")))
|
messageSentAsync.AddBlock(blocks.NewBlock([]byte("data")))
|
||||||
errSending := waiter.SendMessage(
|
errSending := waiter.SendMessage(
|
||||||
context.Background(), mockpeer.WithID(idOfResponder), messageSentAsync)
|
context.Background(), testutil.NewPeerWithID(idOfResponder), messageSentAsync)
|
||||||
if errSending != nil {
|
if errSending != nil {
|
||||||
t.Fatal(errSending)
|
t.Fatal(errSending)
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/jbenet/go-ipfs/importer/chunk"
|
"github.com/jbenet/go-ipfs/importer/chunk"
|
||||||
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
"github.com/jbenet/go-ipfs/util/testutil"
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE:
|
// NOTE:
|
||||||
|
@ -5,13 +5,13 @@ import (
|
|||||||
|
|
||||||
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"
|
||||||
ci "github.com/jbenet/go-ipfs/crypto"
|
ci "github.com/jbenet/go-ipfs/crypto"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
|
||||||
mock "github.com/jbenet/go-ipfs/routing/mock"
|
mock "github.com/jbenet/go-ipfs/routing/mock"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
u "github.com/jbenet/go-ipfs/util"
|
||||||
|
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRoutingResolve(t *testing.T) {
|
func TestRoutingResolve(t *testing.T) {
|
||||||
local := mockpeer.WithIDString("testID")
|
local := testutil.NewPeerWithIDString("testID")
|
||||||
lds := ds.NewMapDatastore()
|
lds := ds.NewMapDatastore()
|
||||||
d := mock.NewMockRouter(local, lds)
|
d := mock.NewMockRouter(local, lds)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
ci "github.com/jbenet/go-ipfs/crypto"
|
ci "github.com/jbenet/go-ipfs/crypto"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
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"
|
||||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||||
@ -22,7 +22,7 @@ func setupPeer(addr string) (peer.Peer, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := mockpeer.WithKeyPair(sk, pk)
|
p, err := testutil.NewPeerWithKeyPair(sk, pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
pb "github.com/jbenet/go-ipfs/net/mux/internal/pb"
|
pb "github.com/jbenet/go-ipfs/net/mux/internal/pb"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
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"
|
||||||
)
|
)
|
||||||
@ -31,7 +31,7 @@ func newPeer(t *testing.T, id string) peer.Peer {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return mockpeer.WithID(peer.ID(mh))
|
return testutil.NewPeerWithID(peer.ID(mh))
|
||||||
}
|
}
|
||||||
|
|
||||||
func testMsg(t *testing.T, m msg.NetMessage, data []byte) {
|
func testMsg(t *testing.T, m msg.NetMessage, data []byte) {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
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"
|
||||||
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
|
||||||
@ -33,7 +33,7 @@ func newPeer(t *testing.T, id string) peer.Peer {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return mockpeer.WithID(peer.ID(mh))
|
return testutil.NewPeerWithID(peer.ID(mh))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceHandler(t *testing.T) {
|
func TestServiceHandler(t *testing.T) {
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
peer "github.com/jbenet/go-ipfs/peer"
|
peer "github.com/jbenet/go-ipfs/peer"
|
||||||
"github.com/jbenet/go-ipfs/peer/mock"
|
"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"
|
||||||
)
|
)
|
||||||
@ -29,7 +29,7 @@ func TestSimultOpen(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
connect := func(s *Swarm, dst peer.Peer) {
|
connect := func(s *Swarm, dst peer.Peer) {
|
||||||
// copy for other peer
|
// copy for other peer
|
||||||
cp := mockpeer.WithID(dst.ID())
|
cp := testutil.NewPeerWithID(dst.ID())
|
||||||
cp.AddAddress(dst.Addresses()[0])
|
cp.AddAddress(dst.Addresses()[0])
|
||||||
|
|
||||||
if _, err := s.Dial(cp); err != nil {
|
if _, err := s.Dial(cp); err != nil {
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
ci "github.com/jbenet/go-ipfs/crypto"
|
ci "github.com/jbenet/go-ipfs/crypto"
|
||||||
msg "github.com/jbenet/go-ipfs/net/message"
|
msg "github.com/jbenet/go-ipfs/net/message"
|
||||||
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"
|
||||||
|
|
||||||
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"
|
||||||
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
|
||||||
@ -44,7 +44,7 @@ func setupPeer(t *testing.T, addr string) peer.Peer {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
p, err := mockpeer.WithKeyPair(sk, pk)
|
p, err := testutil.NewPeerWithKeyPair(sk, pk)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,14 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newPeer(id string) peer.Peer {
|
func newPeer(id string) peer.Peer {
|
||||||
return mockpeer.WithIDString(id)
|
return testutil.NewPeerWithIDString(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueue(t *testing.T) {
|
func TestQueue(t *testing.T) {
|
||||||
@ -70,7 +70,7 @@ func TestQueue(t *testing.T) {
|
|||||||
func newPeerTime(t time.Time) peer.Peer {
|
func newPeerTime(t time.Time) peer.Peer {
|
||||||
s := fmt.Sprintf("hmmm time: %v", t)
|
s := fmt.Sprintf("hmmm time: %v", t)
|
||||||
h := u.Hash([]byte(s))
|
h := u.Hash([]byte(s))
|
||||||
return mockpeer.WithID(peer.ID(h))
|
return testutil.NewPeerWithID(peer.ID(h))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSyncQueue(t *testing.T) {
|
func TestSyncQueue(t *testing.T) {
|
||||||
|
@ -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 {
|
|||||||
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 (
|
|||||||
|
|
||||||
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) {
|
|||||||
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 (
|
|||||||
"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) {
|
|||||||
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 (
|
|||||||
|
|
||||||
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) {
|
|||||||
|
|
||||||
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|||||||
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) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
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")
|
||||||
|
@ -28,6 +28,5 @@ func RandPeer() peer.Peer {
|
|||||||
id := make([]byte, 16)
|
id := make([]byte, 16)
|
||||||
crand.Read(id)
|
crand.Read(id)
|
||||||
mhid := u.Hash(id)
|
mhid := u.Hash(id)
|
||||||
ps := peer.NewPeerstore()
|
return NewPeerWithID(peer.ID(mhid))
|
||||||
return ps.WithID(peer.ID(mhid))
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mockpeer
|
package testutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/jbenet/go-ipfs/peer"
|
"github.com/jbenet/go-ipfs/peer"
|
||||||
@ -6,14 +6,14 @@ import (
|
|||||||
ic "github.com/jbenet/go-ipfs/crypto"
|
ic "github.com/jbenet/go-ipfs/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func WithKeyPair(sk ic.PrivKey, pk ic.PubKey) (peer.Peer, error) {
|
func NewPeerWithKeyPair(sk ic.PrivKey, pk ic.PubKey) (peer.Peer, error) {
|
||||||
return peer.NewPeerstore().WithKeyPair(sk, pk)
|
return peer.NewPeerstore().WithKeyPair(sk, pk)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithID(id peer.ID) peer.Peer {
|
func NewPeerWithID(id peer.ID) peer.Peer {
|
||||||
return peer.NewPeerstore().WithID(id)
|
return peer.NewPeerstore().WithID(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithIDString(id string) peer.Peer {
|
func NewPeerWithIDString(id string) peer.Peer {
|
||||||
return peer.NewPeerstore().WithIDString(id)
|
return peer.NewPeerstore().WithIDString(id)
|
||||||
}
|
}
|
Reference in New Issue
Block a user