Commit 1ccce65f authored by Richer Maximilien's avatar Richer Maximilien

[c] Fix local ip fetch and add test

parent 95f67bf7
Pipeline #1764 passed with stage
......@@ -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(), ':') {
......
......@@ -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!")
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment