13fdf464ae
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package netutil
|
|
|
|
import "testing"
|
|
|
|
func TestIsLocalOrPrivateHost(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
host string
|
|
want bool
|
|
}{
|
|
{name: "localhost", host: "localhost", want: true},
|
|
{name: "localhost subdomain", host: "assets.localhost", want: true},
|
|
{name: "docker host", host: "host.docker.internal", want: true},
|
|
{name: "loopback ipv4", host: "127.0.0.1", want: true},
|
|
{name: "loopback ipv6", host: "::1", want: true},
|
|
{name: "private 10", host: "10.0.0.5", want: true},
|
|
{name: "private 172", host: "172.16.2.3", want: true},
|
|
{name: "private 192", host: "192.168.1.10", want: true},
|
|
{name: "link local", host: "169.254.10.20", want: true},
|
|
{name: "cgnat", host: "100.64.10.20", want: true},
|
|
{name: "unspecified", host: "0.0.0.0", want: true},
|
|
{name: "public ip", host: "8.8.8.8", want: false},
|
|
{name: "public hostname", host: "example.com", want: false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := IsLocalOrPrivateHost(tt.host); got != tt.want {
|
|
t.Fatalf("IsLocalOrPrivateHost(%q) = %t, want %t", tt.host, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|