2019-10-04 22:46:49 +00:00
|
|
|
package iputils_test
|
2019-01-11 01:08:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"regexp"
|
|
|
|
"testing"
|
2019-10-04 22:46:49 +00:00
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/iputils"
|
2019-01-11 01:08:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestExternalIPv4(t *testing.T) {
|
|
|
|
// Regular expression format for IPv4
|
|
|
|
IPv4Format := `\.\d{1,3}\.\d{1,3}\b`
|
2019-10-04 22:46:49 +00:00
|
|
|
test, err := iputils.ExternalIPv4()
|
2019-01-11 01:08:22 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Test check external ipv4 failed with %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
valid := regexp.MustCompile(IPv4Format)
|
|
|
|
|
|
|
|
if !valid.MatchString(test) {
|
|
|
|
t.Errorf("Wanted: %v, got: %v", IPv4Format, test)
|
|
|
|
}
|
|
|
|
}
|