35 lines
890 B
Go
35 lines
890 B
Go
package ipresolve
|
|
|
|
import (
|
|
"context"
|
|
"net/netip"
|
|
"testing"
|
|
)
|
|
|
|
func TestPublicAddress(t *testing.T) {
|
|
t.Parallel()
|
|
for _, raw := range []string{"1.1.1.1", "2001:4860:4860::8888"} {
|
|
address := netip.MustParseAddr(raw)
|
|
if !publicAddress(address) {
|
|
t.Fatalf("expected %s to be public", raw)
|
|
}
|
|
}
|
|
for _, raw := range []string{"127.0.0.1", "192.168.1.1", "169.254.1.1", "::1", "fe80::1"} {
|
|
address := netip.MustParseAddr(raw)
|
|
if publicAddress(address) {
|
|
t.Fatalf("expected %s to be rejected", raw)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDisabledIPv6IsNotResolvedOrReportedAsError(t *testing.T) {
|
|
t.Parallel()
|
|
result := New().ResolveWithIPv6(context.Background(), nil, nil, false)
|
|
if result.IPv4Err == nil {
|
|
t.Fatal("missing IPv4 endpoints should still be reported")
|
|
}
|
|
if result.IPv6 != "" || result.IPv6Err != nil {
|
|
t.Fatalf("disabled IPv6 must be skipped cleanly: %#v", result)
|
|
}
|
|
}
|