Commit 0172e4f2 authored by Brian Tiger Chow's avatar Brian Tiger Chow

style(testutil) rename testutil.Peer -> testutil.Identity

cc @jbenet
parent 2b2ff548
......@@ -61,7 +61,7 @@ func TestProviderForKeyButNetworkCannotFind(t *testing.T) { // TODO revisit this
defer g.Close()
block := blocks.NewBlock([]byte("block"))
pinfo := testutil.RandPeerOrFatal(t)
pinfo := testutil.RandIdentityOrFatal(t)
rs.Client(pinfo).Provide(context.Background(), block.Key()) // but not on network
solo := g.Next()
......
......@@ -7,7 +7,7 @@ import (
)
type Network interface {
Adapter(testutil.Peer) bsnet.BitSwapNetwork
Adapter(testutil.Identity) bsnet.BitSwapNetwork
HasPeer(peer.ID) bool
}
......@@ -17,11 +17,11 @@ import (
func TestSendRequestToCooperativePeer(t *testing.T) {
net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
recipientPeer := testutil.RandPeerOrFatal(t)
recipientPeer := testutil.RandIdentityOrFatal(t)
t.Log("Get two network adapters")
initiator := net.Adapter(testutil.RandPeerOrFatal(t))
initiator := net.Adapter(testutil.RandIdentityOrFatal(t))
recipient := net.Adapter(recipientPeer)
expectedStr := "response from recipient"
......@@ -67,8 +67,8 @@ func TestSendRequestToCooperativePeer(t *testing.T) {
func TestSendMessageAsyncButWaitForResponse(t *testing.T) {
net := VirtualNetwork(mockrouting.NewServer(), delay.Fixed(0))
responderPeer := testutil.RandPeerOrFatal(t)
waiter := net.Adapter(testutil.RandPeerOrFatal(t))
responderPeer := testutil.RandIdentityOrFatal(t)
waiter := net.Adapter(testutil.RandIdentityOrFatal(t))
responder := net.Adapter(responderPeer)
var wg sync.WaitGroup
......
......@@ -19,7 +19,7 @@ func StreamNet(ctx context.Context, net mockpeernet.Mocknet, rs mockrouting.Serv
return &peernet{net, rs}, nil
}
func (pn *peernet) Adapter(p testutil.Peer) bsnet.BitSwapNetwork {
func (pn *peernet) Adapter(p testutil.Identity) bsnet.BitSwapNetwork {
client, err := pn.Mocknet.AddPeer(p.PrivateKey(), p.Address())
if err != nil {
panic(err.Error())
......
......@@ -29,7 +29,7 @@ type network struct {
delay delay.D
}
func (n *network) Adapter(p testutil.Peer) bsnet.BitSwapNetwork {
func (n *network) Adapter(p testutil.Identity) bsnet.BitSwapNetwork {
client := &networkClient{
local: p.ID(),
network: n,
......
......@@ -41,7 +41,7 @@ func (g *SessionGenerator) Close() error {
func (g *SessionGenerator) Next() Instance {
g.seq++
p, err := testutil.RandPeer()
p, err := testutil.RandIdentity()
if err != nil {
panic("FIXME") // TODO change signature
}
......@@ -78,7 +78,7 @@ func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration {
// NB: It's easy make mistakes by providing the same peer ID to two different
// sessions. To safeguard, use the SessionGenerator to generate sessions. It's
// just a much better idea.
func session(ctx context.Context, net tn.Network, p testutil.Peer) Instance {
func session(ctx context.Context, net tn.Network, p testutil.Identity) Instance {
bsdelay := delay.Fixed(0)
const kWriteCacheElems = 100
......
......@@ -10,7 +10,7 @@ import (
)
func TestRoutingResolve(t *testing.T) {
d := mockrouting.NewServer().Client(testutil.RandPeerOrFatal(t))
d := mockrouting.NewServer().Client(testutil.RandIdentityOrFatal(t))
resolver := NewRoutingResolver(d)
publisher := NewRoutingPublisher(d)
......
......@@ -17,7 +17,7 @@ var log = u.Logger("mockrouter")
type client struct {
datastore ds.Datastore
server server
peer testutil.Peer
peer testutil.Identity
}
// FIXME(brian): is this method meant to simulate putting a value into the network?
......
......@@ -73,11 +73,11 @@ func (rs *s) Providers(k u.Key) []peer.PeerInfo {
return ret
}
func (rs *s) Client(p testutil.Peer) Client {
func (rs *s) Client(p testutil.Identity) Client {
return rs.ClientWithDatastore(context.Background(), p, ds.NewMapDatastore())
}
func (rs *s) ClientWithDatastore(_ context.Context, p testutil.Peer, datastore ds.Datastore) Client {
func (rs *s) ClientWithDatastore(_ context.Context, p testutil.Identity, datastore ds.Datastore) Client {
return &client{
peer: p,
datastore: ds.NewMapDatastore(),
......
......@@ -13,7 +13,7 @@ import (
func TestKeyNotFound(t *testing.T) {
var pi = testutil.RandPeerOrFatal(t)
var pi = testutil.RandIdentityOrFatal(t)
var key = u.Key("mock key")
var ctx = context.Background()
......@@ -26,7 +26,7 @@ func TestKeyNotFound(t *testing.T) {
}
func TestClientFindProviders(t *testing.T) {
pi := testutil.RandPeerOrFatal(t)
pi := testutil.RandIdentityOrFatal(t)
rs := NewServer()
client := rs.Client(pi)
......@@ -57,7 +57,7 @@ func TestClientOverMax(t *testing.T) {
k := u.Key("hello")
numProvidersForHelloKey := 100
for i := 0; i < numProvidersForHelloKey; i++ {
pi := testutil.RandPeerOrFatal(t)
pi := testutil.RandIdentityOrFatal(t)
err := rs.Client(pi).Provide(context.Background(), k)
if err != nil {
t.Fatal(err)
......@@ -65,7 +65,7 @@ func TestClientOverMax(t *testing.T) {
}
max := 10
pi := testutil.RandPeerOrFatal(t)
pi := testutil.RandIdentityOrFatal(t)
client := rs.Client(pi)
providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
......@@ -100,7 +100,7 @@ func TestCanceledContext(t *testing.T) {
default:
}
pi, err := testutil.RandPeer()
pi, err := testutil.RandIdentity()
if err != nil {
t.Error(err)
}
......@@ -112,7 +112,7 @@ func TestCanceledContext(t *testing.T) {
}
}()
local := testutil.RandPeerOrFatal(t)
local := testutil.RandIdentityOrFatal(t)
client := rs.Client(local)
t.Log("warning: max is finite so this test is non-deterministic")
......@@ -138,7 +138,7 @@ func TestCanceledContext(t *testing.T) {
func TestValidAfter(t *testing.T) {
pi := testutil.RandPeerOrFatal(t)
pi := testutil.RandIdentityOrFatal(t)
var key = u.Key("mock key")
var ctx = context.Background()
conf := DelayConfig{
......
......@@ -19,11 +19,11 @@ func NewDHTNetwork(mn mocknet.Mocknet) Server {
}
}
func (rs *mocknetserver) Client(p testutil.Peer) Client {
func (rs *mocknetserver) Client(p testutil.Identity) Client {
return rs.ClientWithDatastore(context.TODO(), p, ds.NewMapDatastore())
}
func (rs *mocknetserver) ClientWithDatastore(ctx context.Context, p testutil.Peer, ds ds.Datastore) Client {
func (rs *mocknetserver) ClientWithDatastore(ctx context.Context, p testutil.Identity, ds ds.Datastore) Client {
// FIXME AddPeer doesn't appear to be idempotent
......
......@@ -16,8 +16,8 @@ import (
// Server provides mockrouting Clients
type Server interface {
Client(p testutil.Peer) Client
ClientWithDatastore(context.Context, testutil.Peer, ds.Datastore) Client
Client(p testutil.Identity) Client
ClientWithDatastore(context.Context, testutil.Identity, ds.Datastore) Client
}
// Client implements IpfsRouting
......
......@@ -8,46 +8,46 @@ import (
peer "github.com/jbenet/go-ipfs/peer"
)
type Peer interface {
type Identity interface {
Address() ma.Multiaddr
ID() peer.ID
PrivateKey() ci.PrivKey
PublicKey() ci.PubKey
}
func RandPeer() (Peer, error) {
func RandIdentity() (Identity, error) {
p, err := RandPeerNetParams()
if err != nil {
return nil, err
}
return &testpeer{*p}, nil
return &identity{*p}, nil
}
func RandPeerOrFatal(t *testing.T) Peer {
func RandIdentityOrFatal(t *testing.T) Identity {
p, err := RandPeerNetParams()
if err != nil {
t.Fatal(err)
}
return &testpeer{*p}
return &identity{*p}
}
// peer is a temporary shim to delay binding of PeerNetParams.
type testpeer struct {
// identity is a temporary shim to delay binding of PeerNetParams.
type identity struct {
PeerNetParams
}
func (p *testpeer) ID() peer.ID {
func (p *identity) ID() peer.ID {
return p.PeerNetParams.ID
}
func (p *testpeer) Address() ma.Multiaddr {
func (p *identity) Address() ma.Multiaddr {
return p.Addr
}
func (p *testpeer) PrivateKey() ci.PrivKey {
func (p *identity) PrivateKey() ci.PrivKey {
return p.PrivKey
}
func (p *testpeer) PublicKey() ci.PubKey {
func (p *identity) PublicKey() ci.PubKey {
return p.PubKey
}
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