-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c30702a
commit 8fb9008
Showing
3 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var testCases = []struct { | ||
name string | ||
str string | ||
expected bool | ||
}{ | ||
{"Well-formed IPv4 with port", "127.0.0.1:4443", true}, | ||
{"Well-formed IPv4 without port", "127.0.0.1", false}, | ||
{"Malformed IPv4 with port", "127..0.1:4443", false}, | ||
{"Malformed IPv4 without port", "127..0.1", false}, | ||
{"Well-formed IPv6 with port - 2", "[::1]:4443", true}, | ||
{"Well-formed IPv6 without port", "[fe80::1%25en0]", false}, | ||
{"Malformed IPv6 with port", "[::::1]:4443", false}, | ||
{"Malformed IPv6 without port", "[::::::::1]", false}, | ||
{"Malformed IPv6 : missing square brackets", "::::::::1:4443", false}, | ||
{"Well-formed DNS name with port", "toto.circl.lu:4443", true}, | ||
{"Well-formed DNS name without port", "toto.circl.lu", false}, | ||
{"Malformed DNS name with port", ".:4443", false}, | ||
} | ||
|
||
func TestIsNet(t *testing.T) { | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
b, _ := isNet(tc.str) | ||
if b != tc.expected { | ||
t.Fail() | ||
} | ||
}) | ||
} | ||
} |