Skip to content

Commit

Permalink
add tests for NoTransports and NoListen
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Aug 21, 2018
1 parent ad5b7b9 commit a36d383
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions libp2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

crypto "github.com/libp2p/go-libp2p-crypto"
host "github.com/libp2p/go-libp2p-host"
pstore "github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-tcp-transport"
)

Expand All @@ -32,6 +33,41 @@ func TestBadTransportConstructor(t *testing.T) {
}
}

func TestNoListenAddrs(t *testing.T) {
ctx := context.Background()
h, err := New(ctx, NoListenAddrs)
if err != nil {
t.Fatal(err)
}
defer h.Close()
if len(h.Addrs()) != 0 {
t.Fatal("expected no addresses")
}
}

func TestNoTransports(t *testing.T) {
ctx := context.Background()
a, err := New(ctx, NoTransports)
if err != nil {
t.Fatal(err)
}
defer a.Close()

b, err := New(ctx, ListenAddrStrings("/ip4/127.0.0.1/tcp/0"))
if err != nil {
t.Fatal(err)
}
defer b.Close()

err = a.Connect(ctx, pstore.PeerInfo{
ID: b.ID(),
Addrs: b.Addrs(),
})
if err == nil {
t.Error("dial should have failed as no transports have been configured")
}
}

func TestInsecure(t *testing.T) {
ctx := context.Background()
h, err := New(ctx, NoSecurity)
Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ func NATManager(nm config.NATManagerC) Option {
}
}

// NoListen will configure libp2p to not listen by default.
// NoListenAddrs will configure libp2p to not listen by default.
//
// This will both clear any configured listen addrs and prevent libp2p from
// applying the default listen address option.
var NoListen = func(cfg *Config) error {
var NoListenAddrs = func(cfg *Config) error {
cfg.ListenAddrs = []ma.Multiaddr{}
return nil
}
Expand Down

0 comments on commit a36d383

Please sign in to comment.