OSDN Git Service

Merge pull request #201 from Bytom/v0.1
[bytom/vapor.git] / p2p / external_ip_test.go
diff --git a/p2p/external_ip_test.go b/p2p/external_ip_test.go
new file mode 100644 (file)
index 0000000..18601fe
--- /dev/null
@@ -0,0 +1,22 @@
+package p2p
+
+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)
+       }
+}