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
df2b415f
Commit
df2b415f
authored
Jun 19, 2015
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests for net conversions
License: MIT Signed-off-by:
Juan Batiz-Benet
<
juan@benet.ai
>
parent
b9c1a08d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
net_test.go
net_test.go
+69
-0
No files found.
net_test.go
View file @
df2b415f
...
...
@@ -365,6 +365,75 @@ func TestIP6LinkLocal(t *testing.T) {
}
}
func
TestConvertNetAddr
(
t
*
testing
.
T
)
{
m1
:=
newMultiaddr
(
t
,
"/ip4/1.2.3.4/tcp/4001"
)
n1
,
err
:=
ToNetAddr
(
m1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
m2
,
err
:=
FromNetAddr
(
n1
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
m1
.
String
()
!=
m2
.
String
()
{
t
.
Fatal
(
"ToNetAddr + FromNetAddr did not work"
)
}
}
func
TestWrapNetConn
(
t
*
testing
.
T
)
{
// test WrapNetConn nil
if
_
,
err
:=
WrapNetConn
(
nil
);
err
==
nil
{
t
.
Error
(
"WrapNetConn(nil) should return an error"
)
}
checkErr
:=
func
(
err
error
,
s
string
)
{
if
err
!=
nil
{
t
.
Fatal
(
s
,
err
)
}
}
listener
,
err
:=
net
.
Listen
(
"tcp"
,
"127.0.0.1:0"
)
checkErr
(
err
,
"failed to listen"
)
var
wg
sync
.
WaitGroup
defer
wg
.
Wait
()
wg
.
Add
(
1
)
go
func
()
{
defer
wg
.
Done
()
cB
,
err
:=
listener
.
Accept
()
checkErr
(
err
,
"failed to accept"
)
cB
.
Close
()
}()
cA
,
err
:=
net
.
Dial
(
"tcp"
,
listener
.
Addr
()
.
String
())
checkErr
(
err
,
"failed to dial"
)
defer
cA
.
Close
()
lmaddr
,
err
:=
FromNetAddr
(
cA
.
LocalAddr
())
checkErr
(
err
,
"failed to get local addr"
)
rmaddr
,
err
:=
FromNetAddr
(
cA
.
RemoteAddr
())
checkErr
(
err
,
"failed to get remote addr"
)
mcA
,
err
:=
WrapNetConn
(
cA
)
checkErr
(
err
,
"failed to wrap conn"
)
if
mcA
.
LocalAddr
()
.
String
()
!=
cA
.
LocalAddr
()
.
String
()
{
t
.
Error
(
"wrapped conn local addr differs"
)
}
if
mcA
.
RemoteAddr
()
.
String
()
!=
cA
.
RemoteAddr
()
.
String
()
{
t
.
Error
(
"wrapped conn remote addr differs"
)
}
if
mcA
.
LocalMultiaddr
()
.
String
()
!=
lmaddr
.
String
()
{
t
.
Error
(
"wrapped conn local maddr differs"
)
}
if
mcA
.
RemoteMultiaddr
()
.
String
()
!=
rmaddr
.
String
()
{
t
.
Error
(
"wrapped conn remote maddr differs"
)
}
}
func
TestAddrMatch
(
t
*
testing
.
T
)
{
test
:=
func
(
m
ma
.
Multiaddr
,
input
,
expect
[]
ma
.
Multiaddr
)
{
...
...
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