Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
ecf27b59
Commit
ecf27b59
authored
6 years ago
by
Abhishek Upperwal
Browse files
Options
Download
Email Patches
Plain Diff
strict DefaultListenAddrs test w/ regex
parent
6372f928
master
2018-Q4-OKR
feat/protobuf
fix/473
fix/no-custom-field
fix/revert-correct-external-addr
multistream-ping
punching
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libp2p_test.go
+9
-18
libp2p_test.go
with
9 additions
and
18 deletions
+9
-18
libp2p_test.go
View file @
ecf27b59
...
...
@@ -3,6 +3,7 @@ package libp2p
import
(
"context"
"fmt"
"regexp"
"strings"
"testing"
...
...
@@ -43,14 +44,19 @@ func TestInsecure(t *testing.T) {
func
TestDefaultListenAddrs
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
re
:=
regexp
.
MustCompile
(
"/ip[4|6]/0.0.0.0/tcp/"
)
// Test 1: Setting the correct listen addresses if userDefined.Transport == nil && userDefined.ListenAddrs == nil
h
,
err
:=
New
(
ctx
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
len
(
h
.
Addrs
())
!=
2
{
t
.
Error
(
"expected 2 default listen addrs"
)
for
_
,
addr
:=
range
h
.
Network
()
.
ListenAddresses
()
{
if
re
.
FindStringSubmatchIndex
(
addr
.
String
())
==
nil
{
t
.
Error
(
"expected ip4 or ip6 interface"
)
}
}
h
.
Close
()
// Test 2: Listen addr should not set if user defined transport is passed.
...
...
@@ -62,25 +68,10 @@ func TestDefaultListenAddrs(t *testing.T) {
t
.
Fatal
(
err
)
}
if
len
(
h
.
Addr
s
())
!=
0
{
if
len
(
h
.
Network
()
.
ListenAddresse
s
())
!=
0
{
t
.
Error
(
"expected zero listen addrs as none is set with user defined transport"
)
}
h
.
Close
()
// Test 3: User defined listener addrs should overwrite the default options.
h
,
err
=
New
(
ctx
,
Transport
(
tcp
.
NewTCPTransport
),
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
)
{
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help