Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
fad8780c
Commit
fad8780c
authored
Mar 08, 2018
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add test for netlistener wrapper/unwrapper
parent
1e79033a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
net_test.go
net_test.go
+54
-0
No files found.
net_test.go
View file @
fad8780c
...
...
@@ -514,3 +514,57 @@ func TestInterfaceAddressesWorks(t *testing.T) {
t
.
Fatal
(
err
)
}
}
func
TestNetListener
(
t
*
testing
.
T
)
{
listener
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:1234"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
listener
.
Close
()
malist
,
err
:=
WrapNetListener
(
listener
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
malist
.
Multiaddr
()
.
Equal
(
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
))
{
t
.
Fatal
(
"unexpected multiaddr"
)
}
go
func
()
{
c
,
err
:=
Dial
(
malist
.
Multiaddr
())
if
err
!=
nil
{
t
.
Fatal
(
"failed to dial"
)
}
if
!
c
.
RemoteMultiaddr
()
.
Equal
(
malist
.
Multiaddr
())
{
t
.
Fatal
(
"dialed wrong target"
)
}
c
.
Close
()
c
,
err
=
Dial
(
malist
.
Multiaddr
())
if
err
!=
nil
{
t
.
Fatal
(
"failed to dial"
)
}
c
.
Close
()
}()
c
,
err
:=
malist
.
Accept
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
c
.
Close
()
netList
:=
NetListener
(
malist
)
malist2
,
err
:=
WrapNetListener
(
netList
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
malist2
!=
malist
{
t
.
Fatal
(
"expected WrapNetListener(NetListener(malist)) == malist"
)
}
nc
,
err
:=
netList
.
Accept
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
nc
.
(
Conn
)
.
LocalMultiaddr
()
.
Equal
(
malist
.
Multiaddr
())
{
t
.
Fatal
(
"wrong multiaddr on conn"
)
}
nc
.
Close
()
}
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