Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mpcs
dfss
Commits
1ccce65f
Commit
1ccce65f
authored
May 18, 2016
by
Richer Maximilien
Browse files
[c] Fix local ip fetch and add test
parent
95f67bf7
Pipeline
#1764
passed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
net/client.go
View file @
1ccce65f
...
...
@@ -154,8 +154,8 @@ func ExternalInterfaceAddr() ([]string, error) {
return
nil
,
err
}
var
extAddrs
=
make
([]
string
,
len
(
addrs
)
)
var
localhostAddrs
=
make
([]
string
,
1
)
var
extAddrs
=
make
([]
string
,
0
)
var
localhostAddrs
=
make
([]
string
,
0
)
for
_
,
a
:=
range
addrs
{
if
strings
.
ContainsRune
(
a
.
String
(),
':'
)
{
...
...
net/net_test.go
View file @
1ccce65f
...
...
@@ -3,6 +3,7 @@ package net
import
(
"fmt"
"net"
"regexp"
"testing"
"time"
...
...
@@ -253,3 +254,19 @@ func Example() {
// 42
// 43
}
// INTERFACE TEST
func
TestExternalInterfaces
(
t
*
testing
.
T
)
{
ips
,
err
:=
ExternalInterfaceAddr
()
if
err
!=
nil
{
panic
(
"Cannot read interfaces config"
)
}
isAnIpV4
:=
regexp
.
MustCompile
(
"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
)
for
_
,
ip
:=
range
ips
{
if
!
isAnIpV4
.
MatchString
(
ip
)
{
panic
(
ip
+
" is not a valid IPv4!"
)
}
}
}
Write
Preview
Supports
Markdown
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