This repository has been archived by the owner on Dec 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package host_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
host "github.com/libp2p/go-libp2p-host" | ||
ifconnmgr "github.com/libp2p/go-libp2p-interface-connmgr" | ||
inet "github.com/libp2p/go-libp2p-net" | ||
peer "github.com/libp2p/go-libp2p-peer" | ||
pt "github.com/libp2p/go-libp2p-peer/test" | ||
pstore "github.com/libp2p/go-libp2p-peerstore" | ||
protocol "github.com/libp2p/go-libp2p-protocol" | ||
ma "github.com/multiformats/go-multiaddr" | ||
msmux "github.com/multiformats/go-multistream" | ||
) | ||
|
||
var ( | ||
peerID, _ = pt.RandPeerID() | ||
addr1, _ = ma.NewMultiaddr("/ip4/1.1.1.1") | ||
addr2, _ = ma.NewMultiaddr("/ip4/2.2.2.2") | ||
) | ||
|
||
type mockHost struct{} | ||
|
||
func (*mockHost) ID() peer.ID { | ||
return peerID | ||
} | ||
|
||
func (*mockHost) Peerstore() pstore.Peerstore { | ||
return nil | ||
} | ||
|
||
func (*mockHost) Addrs() []ma.Multiaddr { | ||
return []ma.Multiaddr{addr1, addr2} | ||
} | ||
|
||
func (*mockHost) Network() inet.Network { | ||
return nil | ||
} | ||
|
||
func (*mockHost) Mux() *msmux.MultistreamMuxer { | ||
return nil | ||
} | ||
|
||
func (*mockHost) Connect(ctx context.Context, pi pstore.PeerInfo) error { | ||
return nil | ||
} | ||
|
||
func (*mockHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler) { | ||
} | ||
|
||
func (*mockHost) SetStreamHandlerMatch(protocol.ID, func(string) bool, inet.StreamHandler) { | ||
} | ||
|
||
func (*mockHost) RemoveStreamHandler(pid protocol.ID) { | ||
} | ||
|
||
func (*mockHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (inet.Stream, error) { | ||
return nil, nil | ||
} | ||
|
||
func (*mockHost) Close() error { | ||
return nil | ||
} | ||
|
||
func (*mockHost) ConnManager() ifconnmgr.ConnManager { | ||
return nil | ||
} | ||
|
||
var _ host.Host = (*mockHost)(nil) | ||
|
||
func TestPeerInfoFromHost(t *testing.T) { | ||
h := &mockHost{} | ||
pi := host.PeerInfoFromHost(h) | ||
|
||
if pi.ID != peerID || !pi.Addrs[0].Equal(addr1) || !pi.Addrs[1].Equal(addr2) { | ||
t.Error("unexpected PeerInfo from Host") | ||
} | ||
|
||
} |