check / check (push) Canceled after 0s
The README, the comments and TODO.md say the health check gives error only when every lookup in a round failed because no root server gave a usable reply, and the README drops the claim that the other failures are reported as notifications. Model: opus-5-5
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
package watcher_test
|
|
|
|
import (
|
|
"log/slog"
|
|
"testing"
|
|
|
|
"sneak.berlin/go/dnswatcher/internal/resolver"
|
|
"sneak.berlin/go/dnswatcher/internal/watcher"
|
|
)
|
|
|
|
// TestDNSUnreachableWhenNoRootServerReplies runs one round of checks of
|
|
// a domain and a hostname with every walk starting at real servers that
|
|
// are not root servers. At 192.0.2.1, a documentation address, nothing
|
|
// answers, as when no root server answers. Public recursive resolvers of
|
|
// four operators mark their replies recursion available, as on a network
|
|
// that intercepts DNS queries; one that gives no reply is passed over
|
|
// for the next, and if none replies, no root server answered. Either
|
|
// way every lookup failed because no root server gave a usable reply,
|
|
// so the round could not reach the DNS. TestFirstRunBaseline and
|
|
// TestDomainThatDoesNotExist check rounds in which the root servers
|
|
// gave a usable reply.
|
|
func TestDNSUnreachableWhenNoRootServerReplies(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
servers []string
|
|
}{
|
|
{"no root server answers", []string{"192.0.2.1"}},
|
|
{
|
|
"the network intercepts DNS queries",
|
|
[]string{"1.1.1.1", "8.8.8.8", "9.9.9.9", "208.67.222.222"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
cfg := defaultTestConfig(t)
|
|
cfg.Domains = []string{testSmallDomain}
|
|
cfg.Hostnames = []string{testHost}
|
|
|
|
deps := newTestDeps(t, cfg)
|
|
w := watcher.NewForTest(
|
|
cfg,
|
|
deps.state,
|
|
resolver.NewWithRootServers(slog.Default(), tt.servers),
|
|
deps.portChecker,
|
|
deps.tlsChecker,
|
|
deps.notifier,
|
|
)
|
|
|
|
if w.DNSUnreachable() {
|
|
t.Error("DNSUnreachable is true before the first round")
|
|
}
|
|
|
|
w.RunOnce(t.Context())
|
|
|
|
if !w.DNSUnreachable() {
|
|
t.Error("DNSUnreachable is false after a round in " +
|
|
"which no root server gave a usable reply")
|
|
}
|
|
})
|
|
}
|
|
}
|