Commit 414ff341 authored by Jeromy's avatar Jeromy Committed by Brian Tiger Chow

change back to using Client method

parent c45cc8c4
......@@ -281,8 +281,7 @@ func session(net tn.Network, rs mock.RoutingServer, id peer.ID) instance {
p := &peer.Peer{ID: id}
adapter := net.Adapter(p)
htc := mock.NewMockRouter(p, nil)
htc.SetRoutingServer(rs)
htc := rs.Client(p)
blockstore := bstore.NewBlockstore(ds.NewMapDatastore())
const alwaysSendToPeer = true
......
......@@ -43,12 +43,10 @@ func TestSetAndGet(t *testing.T) {
}
func TestClientFindProviders(t *testing.T) {
peer := &peer.Peer{
ID: []byte("42"),
}
peer := &peer.Peer{ID: []byte("42")}
rs := mock.VirtualRoutingServer()
client := mock.NewMockRouter(peer, nil)
client.SetRoutingServer(rs)
client := rs.Client(peer)
k := u.Key("hello")
err := client.Provide(context.Background(), k)
if err != nil {
......@@ -99,8 +97,9 @@ func TestClientOverMax(t *testing.T) {
}
max := 10
client := mock.NewMockRouter(&peer.Peer{ID: []byte("TODO")}, nil)
client.SetRoutingServer(rs)
peer := &peer.Peer{ID: []byte("TODO")}
client := rs.Client(peer)
providersFromClient := client.FindProvidersAsync(context.Background(), k, max)
i := 0
for _ = range providersFromClient {
......@@ -132,8 +131,7 @@ func TestCanceledContext(t *testing.T) {
}()
local := &peer.Peer{ID: []byte("peer id doesn't matter")}
client := mock.NewMockRouter(local, nil)
client.SetRoutingServer(rs)
client := rs.Client(local)
t.Log("warning: max is finite so this test is non-deterministic")
t.Log("context cancellation could simply take lower priority")
......
......@@ -20,7 +20,7 @@ type MockRouter struct {
peer *peer.Peer
}
func NewMockRouter(local *peer.Peer, dstore ds.Datastore) *MockRouter {
func NewMockRouter(local *peer.Peer, dstore ds.Datastore) routing.IpfsRouting {
return &MockRouter{
datastore: dstore,
peer: local,
......@@ -84,6 +84,8 @@ type RoutingServer interface {
Announce(*peer.Peer, u.Key) error
Providers(u.Key) []*peer.Peer
Client(p *peer.Peer) routing.IpfsRouting
}
func VirtualRoutingServer() RoutingServer {
......@@ -128,3 +130,10 @@ func (rs *hashTable) Providers(k u.Key) []*peer.Peer {
return ret
}
func (rs *hashTable) Client(p *peer.Peer) routing.IpfsRouting {
return &MockRouter{
peer: p,
hashTable: rs,
}
}
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