initial commit

This commit is contained in:
Benjamin Bärthlein
2020-03-28 17:56:11 +01:00
parent 4a3673e0d3
commit c4809b85b4
51 changed files with 26929 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
package ipparser
import (
"net"
)
func ValidIP4(ipAddress string) bool {
testInput := net.ParseIP(ipAddress)
if testInput == nil {
return false
}
return (testInput.To4() != nil)
}
func ValidIP6(ip6Address string) bool {
testInputIP6 := net.ParseIP(ip6Address)
if testInputIP6 == nil {
return false
}
return (testInputIP6.To16() != nil)
}
+29
View File
@@ -0,0 +1,29 @@
package ipparser
import (
"testing"
)
func TestValidIP4ToReturnTrueOnValidAddress(t *testing.T) {
result := ValidIP4("1.2.3.4")
if result != true {
t.Fatalf("Expected ValidIP(1.2.3.4) to be true but got false")
}
}
func TestValidIP4ToReturnFalseOnInvalidAddress(t *testing.T) {
result := ValidIP4("abcd")
if result == true {
t.Fatalf("Expected ValidIP(abcd) to be false but got true")
}
}
func TestValidIP4ToReturnFalseOnEmptyAddress(t *testing.T) {
result := ValidIP4("")
if result == true {
t.Fatalf("Expected ValidIP() to be false but got true")
}
}