All checks were successful
check / check (push) Successful in 31s
Pin golangci-lint to commit c0d3ddc9cf3faa61a4e378e879ece580256d76e5 (v2.12.2) in Dockerfile and script/bootstrap. Replace .golangci.yml with a v2-schema migration of the canonical config, produced with golangci-lint migrate (owner-authorized; the same file becomes the new org-wide canonical via a prompts-repo PR). Lint settings now live under linters.settings, so the lll, funlen, cyclop, and dupl thresholds are actually applied. The deprecated gomodguard linter is disabled in favor of gomodguard_v2, resolving the v2.12 deprecation warning. Deliberate delta from the migrate output: the gci formatter is not enabled because its default two-group import ordering conflicts with the repo's stdlib/third-party/local import style that script/fmt (gofmt + goimports) produces. Fix all findings surfaced by the now-active thresholds: - goconst: shared constants for repeated status, priority, and DNS fixture strings in watcher.go and the notify, state, and watcher tests - dupl: consolidate duplicated ntfy/slack HTTP-error tests and SendNotification endpoint-error tests behind shared helpers - lll: wrap long test table entries and comments; shorten one inline nolint justification
104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package config_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"sneak.berlin/go/dnswatcher/internal/config"
|
|
)
|
|
|
|
func TestClassifyDNSName(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want config.DNSNameType
|
|
wantErr bool
|
|
}{
|
|
{name: "apex domain simple", input: "example.com", want: config.DNSNameTypeDomain},
|
|
{name: "hostname simple", input: "www.example.com", want: config.DNSNameTypeHostname},
|
|
{
|
|
name: "apex domain multi-part TLD",
|
|
input: "example.co.uk",
|
|
want: config.DNSNameTypeDomain,
|
|
},
|
|
{
|
|
name: "hostname multi-part TLD",
|
|
input: "api.example.co.uk",
|
|
want: config.DNSNameTypeHostname,
|
|
},
|
|
{name: "public suffix itself", input: "co.uk", wantErr: true},
|
|
{name: "empty string", input: "", wantErr: true},
|
|
{
|
|
name: "deeply nested hostname",
|
|
input: "a.b.c.example.com",
|
|
want: config.DNSNameTypeHostname,
|
|
},
|
|
{
|
|
name: "trailing dot stripped",
|
|
input: "example.com.",
|
|
want: config.DNSNameTypeDomain,
|
|
},
|
|
{
|
|
name: "uppercase normalized",
|
|
input: "WWW.Example.COM",
|
|
want: config.DNSNameTypeHostname,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
got, err := config.ClassifyDNSName(tt.input)
|
|
|
|
if tt.wantErr {
|
|
if err == nil {
|
|
t.Errorf("ClassifyDNSName(%q) expected error, got %v", tt.input, got)
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
if err != nil {
|
|
t.Fatalf("ClassifyDNSName(%q) unexpected error: %v", tt.input, err)
|
|
}
|
|
|
|
if got != tt.want {
|
|
t.Errorf("ClassifyDNSName(%q) = %v, want %v", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestClassifyTargets(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
domains, hostnames, err := config.ClassifyTargets([]string{
|
|
"example.com",
|
|
"www.example.com",
|
|
"example.co.uk",
|
|
"api.example.co.uk",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if len(domains) != 2 {
|
|
t.Errorf("expected 2 domains, got %d: %v", len(domains), domains)
|
|
}
|
|
|
|
if len(hostnames) != 2 {
|
|
t.Errorf("expected 2 hostnames, got %d: %v", len(hostnames), hostnames)
|
|
}
|
|
}
|
|
|
|
func TestClassifyTargetsRejectsPublicSuffix(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, _, err := config.ClassifyTargets([]string{"co.uk"})
|
|
if err == nil {
|
|
t.Error("expected error for public suffix, got nil")
|
|
}
|
|
}
|