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
c9acf9f2
Unverified
Commit
c9acf9f2
authored
Sep 30, 2019
by
Steven Allen
Committed by
GitHub
Sep 30, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #60 from multiformats/feat/test-unix
test: test unix addrs
parents
a5c136c9
2646b1d6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
convert.go
convert.go
+18
-2
convert_test.go
convert_test.go
+19
-0
No files found.
convert.go
View file @
c9acf9f2
...
...
@@ -4,6 +4,8 @@ import (
"fmt"
"net"
"path/filepath"
"runtime"
"strings"
ma
"github.com/multiformats/go-multiaddr"
)
...
...
@@ -192,6 +194,10 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
}
return
network
,
"["
+
ip
+
"]"
+
":"
+
port
,
nil
case
"unix"
:
if
runtime
.
GOOS
==
"windows"
{
// convert /c:/... to c:\...
ip
=
filepath
.
FromSlash
(
strings
.
TrimLeft
(
ip
,
"/"
))
}
return
network
,
ip
,
nil
default
:
return
""
,
""
,
fmt
.
Errorf
(
"%s is not a 'thin waist' address"
,
m
)
...
...
@@ -263,6 +269,16 @@ func parseUnixNetAddr(a net.Addr) (ma.Multiaddr, error) {
if
!
ok
{
return
nil
,
errIncorrectNetAddr
}
cleaned
:=
filepath
.
Clean
(
ac
.
Name
)
return
ma
.
NewComponent
(
"unix"
,
cleaned
)
path
:=
ac
.
Name
if
runtime
.
GOOS
==
"windows"
{
// Convert c:\foobar\... to c:/foobar/...
path
=
filepath
.
ToSlash
(
path
)
}
if
len
(
path
)
==
0
||
path
[
0
]
!=
'/'
{
// convert "" and "c:/..." to "/..."
path
=
"/"
+
path
}
return
ma
.
NewComponent
(
"unix"
,
path
)
}
convert_test.go
View file @
c9acf9f2
...
...
@@ -2,6 +2,7 @@ package manet
import
(
"net"
"runtime"
"testing"
ma
"github.com/multiformats/go-multiaddr"
...
...
@@ -64,6 +65,24 @@ func TestFromIP4(t *testing.T) {
})
}
func
TestFromUnix
(
t
*
testing
.
T
)
{
path
:=
"/C:/foo/bar"
if
runtime
.
GOOS
==
"windows"
{
path
=
`C:\foo\bar`
}
testConvert
(
t
,
"/unix/C:/foo/bar"
,
func
()
(
ma
.
Multiaddr
,
error
)
{
return
FromNetAddr
(
&
net
.
UnixAddr
{
Name
:
path
,
Net
:
"unix"
})
})
}
func
TestToUnix
(
t
*
testing
.
T
)
{
path
:=
"/C:/foo/bar"
if
runtime
.
GOOS
==
"windows"
{
path
=
`C:\foo\bar`
}
testToNetAddr
(
t
,
"/unix/C:/foo/bar"
,
"unix"
,
path
)
}
func
TestFromIP6
(
t
*
testing
.
T
)
{
testConvert
(
t
,
"/ip6/2001:4860:0:2001::68"
,
func
()
(
ma
.
Multiaddr
,
error
)
{
return
FromNetAddr
(
&
net
.
IPAddr
{
IP
:
net
.
ParseIP
(
"2001:4860:0:2001::68"
)})
...
...
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