Skip to content

Commit 0648439

Browse files
committed
Add table test for private IPs
1 parent 92f5f6d commit 0648439

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

http/http_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,23 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
)
1313

14-
type countServer struct {
15-
count int
16-
}
14+
func TestIsPrivateIP(t *testing.T) {
15+
tests := []struct {
16+
ip string
17+
expected bool
18+
}{
19+
{"216.58.194.206", false},
20+
{"127.0.0.1", true},
21+
{"10.0.0.1", true},
22+
{"192.168.0.1", true},
23+
{"172.16.0.0", true},
24+
{"169.254.169.254", true},
25+
}
1726

18-
func (c *countServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
27+
for _, tt := range tests {
28+
ip := net.ParseIP(tt.ip)
29+
assert.Equal(t, tt.expected, isPrivateIP(ip))
30+
}
1931
}
2032

2133
func TestSafeHTTPClient(t *testing.T) {

0 commit comments

Comments
 (0)