105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package checker
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSelectedResolvers_DefaultExcludesFiltered(t *testing.T) {
|
|
out := selectedResolvers(false, "all", nil)
|
|
if len(out) == 0 {
|
|
t.Fatalf("default selection is empty")
|
|
}
|
|
for _, r := range out {
|
|
if r.Filtered {
|
|
t.Errorf("filtered resolver %q leaked into default selection", r.ID)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSelectedResolvers_IncludeFiltered(t *testing.T) {
|
|
withF := selectedResolvers(true, "all", nil)
|
|
withoutF := selectedResolvers(false, "all", nil)
|
|
if len(withF) <= len(withoutF) {
|
|
t.Errorf("includeFiltered=true should add resolvers, got %d vs %d", len(withF), len(withoutF))
|
|
}
|
|
}
|
|
|
|
func TestSelectedResolvers_RegionFilter(t *testing.T) {
|
|
out := selectedResolvers(false, "eu", nil)
|
|
if len(out) == 0 {
|
|
t.Fatalf("eu selection is empty")
|
|
}
|
|
for _, r := range out {
|
|
if r.Region != "eu" {
|
|
t.Errorf("non-eu resolver %q (%s) leaked in", r.ID, r.Region)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestSelectedResolvers_AllowlistByID(t *testing.T) {
|
|
out := selectedResolvers(false, "all", []string{"cloudflare", "9.9.9.10"})
|
|
ids := make(map[string]bool)
|
|
for _, r := range out {
|
|
ids[r.ID] = true
|
|
}
|
|
if !ids["cloudflare"] || !ids["quad9-unfiltered"] {
|
|
t.Errorf("allowlist failed: %v", ids)
|
|
}
|
|
if len(out) != 2 {
|
|
t.Errorf("expected exactly 2 resolvers, got %d", len(out))
|
|
}
|
|
}
|
|
|
|
func TestSelectedResolvers_AllowlistOverridesFilteredAndRegion(t *testing.T) {
|
|
// quad9 is Filtered + global; allowlist must still pick it.
|
|
out := selectedResolvers(false, "eu", []string{"quad9"})
|
|
if len(out) != 1 || out[0].ID != "quad9" {
|
|
t.Errorf("allowlist should override filtered/region, got %v", out)
|
|
}
|
|
}
|
|
|
|
func TestRegionLabel(t *testing.T) {
|
|
cases := map[string]string{
|
|
"global": "Global / Anycast",
|
|
"na": "North America",
|
|
"eu": "Europe",
|
|
"asia": "Asia",
|
|
"ru": "Russia",
|
|
"me": "Middle East",
|
|
"oceania": "Oceania",
|
|
"sa": "South America",
|
|
"africa": "Africa",
|
|
"unknown": "unknown",
|
|
"": "",
|
|
}
|
|
for in, want := range cases {
|
|
if got := regionLabel(in); got != want {
|
|
t.Errorf("regionLabel(%q) = %q, want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAllResolversCatalogIntegrity(t *testing.T) {
|
|
// Catch typos / duplicates in the static catalog.
|
|
ids := map[string]bool{}
|
|
for _, r := range allResolvers {
|
|
if r.ID == "" {
|
|
t.Errorf("resolver with empty ID: %+v", r)
|
|
}
|
|
if r.IP == "" {
|
|
t.Errorf("resolver %q has empty IP", r.ID)
|
|
}
|
|
if strings.Contains(r.ID, "|") {
|
|
t.Errorf("resolver ID %q contains reserved separator '|'", r.ID)
|
|
}
|
|
if ids[r.ID] {
|
|
t.Errorf("duplicate resolver ID %q", r.ID)
|
|
}
|
|
ids[r.ID] = true
|
|
if r.DoTHost == "" && r.DoHURL != "" {
|
|
// DoH-only is acceptable but log it for visibility.
|
|
t.Logf("resolver %q has DoH but no DoT", r.ID)
|
|
}
|
|
}
|
|
}
|