github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/p2p/external_ip_test.go (about) 1 package p2p 2 3 import ( 4 "regexp" 5 "testing" 6 ) 7 8 func TestExternalIPv4(t *testing.T) { 9 // Regular expression format for IPv4 10 IPv4Format := `\.\d{1,3}\.\d{1,3}\b` 11 test, err := ExternalIPv4() 12 13 if err != nil { 14 t.Errorf("Test check external ipv4 failed with %v", err) 15 } 16 17 valid := regexp.MustCompile(IPv4Format) 18 19 if !valid.MatchString(test) { 20 t.Errorf("Wanted: %v, got: %v", IPv4Format, test) 21 } 22 }