Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
fb401957
Commit
fb401957
authored
Jul 26, 2018
by
Abhishek Upperwal
Browse files
Added test for DefaultListenAddrs
parent
836d042f
Changes
1
Hide whitespace changes
Inline
Side-by-side
libp2p_test.go
View file @
fb401957
...
...
@@ -8,6 +8,7 @@ import (
crypto
"github.com/libp2p/go-libp2p-crypto"
host
"github.com/libp2p/go-libp2p-host"
"github.com/libp2p/go-tcp-transport"
)
func
TestNewHost
(
t
*
testing
.
T
)
{
...
...
@@ -39,6 +40,39 @@ func TestInsecure(t *testing.T) {
h
.
Close
()
}
func
TestDefaultListenAddrs
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
// Test 1: Listen addr should not set if user defined transport is passed.
h
,
err
:=
New
(
ctx
,
Transport
(
tcp
.
TcpTransport
{}),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
h
.
Addrs
())
!=
0
{
t
.
Error
(
"expected zero listen addrs as none is set with user defined transport"
)
}
h
.
Close
()
// Test 2: User defined listener addrs should overwrite the default options.
h
,
err
=
New
(
ctx
,
Transport
(
tcp
.
TcpTransport
{}),
ListenAddrStrings
(
"/ip4/127.0.0.1/tcp/0"
),
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
h
.
Addrs
())
!=
1
{
t
.
Error
(
"expected one listen addr"
)
}
h
.
Close
()
}
func
makeRandomHost
(
t
*
testing
.
T
,
port
int
)
(
host
.
Host
,
error
)
{
ctx
:=
context
.
Background
()
priv
,
_
,
err
:=
crypto
.
GenerateKeyPair
(
crypto
.
RSA
,
2048
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment