Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
add a test for helper.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Oct 24, 2018
1 parent 16daa76 commit 4474f22
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions helpers_test.go
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")
}

}

0 comments on commit 4474f22

Please sign in to comment.