prysm-pulse/shared/iputils/external_ip_test.go
Preethesh Puthran afcfc47273 Added tests for iputils (#1265)
* Added tests for iputils

These tests reference issue #1264 on prysm.
The purpose behind the changes is to validate
results of the return value for the function
ExternalIPv4. Using regular expressions to validate
the ip address. Bazel build configuration has also
been updated.

* Added tests for iputils

These tests reference issue #1264 on prysm.
The purpose behind the changes is to validate
results of the return value for the function
ExternalIPv4. Using regular expressions to validate
the ip address. Bazel build configuration has also
been updated.

* Updated external_ip_test
2019-01-10 20:08:22 -05:00

23 lines
405 B
Go

package iputils
import (
"regexp"
"testing"
)
func TestExternalIPv4(t *testing.T) {
// Regular expression format for IPv4
IPv4Format := `\.\d{1,3}\.\d{1,3}\b`
test, err := ExternalIPv4()
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)
}
}