Skip to content

Commit

Permalink
IPv4 and IPv6 tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cinar committed Jun 17, 2023
1 parent 9c09f2d commit 0ae153e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ipv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ func TestIsIpV4Invalid(t *testing.T) {
}
}

func TestIsIpV4InvalidV6(t *testing.T) {
if IsIpV4("2001:db8::68") == ResultValid {
t.Fail()
}
}

func TestIsIpV4Valid(t *testing.T) {
if IsIpV4("192.168.1.1") != ResultValid {
t.Fail()
Expand Down
2 changes: 1 addition & 1 deletion ipv6.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func IsIpV6(value string) Result {
return ResultNotIpV6
}

if ip.To16() == nil {
if ip.To4() != nil {
return ResultNotIpV6
}

Expand Down
6 changes: 6 additions & 0 deletions ipv6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ func TestIsIpV6Invalid(t *testing.T) {
}
}

func TestIsIpV6InvalidV4(t *testing.T) {
if IsIpV6("192.168.1.1") == ResultValid {
t.Fail()
}
}

func TestIsIpV6Valid(t *testing.T) {
if IsIpV6("2001:db8::68") != ResultValid {
t.Fail()
Expand Down

0 comments on commit 0ae153e

Please sign in to comment.