Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff66ecc0c9 |
+23
-20
@@ -1,27 +1,13 @@
|
||||
# Lint stage - fast feedback on lint issues, before the build starts.
|
||||
# The linter is invoked directly rather than through `make lint`: that
|
||||
# target shells out to `docker build -f Dockerfile.lint`, and there is
|
||||
# no docker daemon inside a docker build.
|
||||
# golangci/golangci-lint:v2.12.2 (Debian-based), 2026-08-10
|
||||
FROM golangci/golangci-lint:v2.12.2@sha256:5cceeef04e53efe1470638d4b4b4f5ceefd574955ab3941b2d9a68a8c9ad5240 AS lint
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN make fmt-check
|
||||
RUN golangci-lint run --config .golangci.yml ./...
|
||||
|
||||
# Build stage
|
||||
# golang 1.25-alpine, 2026-02-28
|
||||
FROM golang@sha256:f6751d823c26342f9506c03797d2527668d095b0a15f1862cddb4d927a7a4ced AS builder
|
||||
|
||||
RUN apk add --no-cache git make gcc musl-dev binutils-gold
|
||||
|
||||
# Force BuildKit to run the lint stage before proceeding
|
||||
COPY --from=lint /src/go.sum /dev/null
|
||||
# golangci-lint v2.12.2, 2026-08-07
|
||||
RUN go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5
|
||||
# goimports v0.42.0
|
||||
RUN go install golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0
|
||||
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum ./
|
||||
@@ -29,8 +15,25 @@ RUN go mod download
|
||||
|
||||
COPY . .
|
||||
|
||||
# Run the tests - build fails if any test fails
|
||||
RUN make test
|
||||
# Run all checks - build fails if any check fails.
|
||||
#
|
||||
# CHECK_EPOCH is a cache-busting build argument. Without it, an
|
||||
# unchanged tree leaves this layer's cache key identical and Docker
|
||||
# serves the previous verdict instead of re-running the suite, so the
|
||||
# build reports a green it did not earn. A build argument's value
|
||||
# participates in the cache key of later instructions in the stage even
|
||||
# when they do not reference it, so a fresh value busts this layer
|
||||
# either way. It is expanded into the command deliberately: that makes
|
||||
# the invalidation a property of the command string itself rather than
|
||||
# of how a given builder treats unreferenced args, and it surfaces the
|
||||
# epoch in the build log as a diagnostic.
|
||||
#
|
||||
# Placing the ARG here and nowhere earlier keeps everything above it
|
||||
# (toolchain install, go mod download) cached, so only the check and the
|
||||
# steps after it re-run. script/cibuild passes a fresh value per run; a
|
||||
# plain `docker build` without it caches as before.
|
||||
ARG CHECK_EPOCH
|
||||
RUN echo "check epoch: ${CHECK_EPOCH}" && make check
|
||||
|
||||
# Build the binary
|
||||
RUN make build
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
# Lint-only image: used by script/lint. golangci-lint is never run on
|
||||
# the host — the repo is COPYed into the build context and the linter
|
||||
# runs as a build step, so a successful build IS a clean lint. This
|
||||
# also works where the docker daemon is remote and bind mounts are
|
||||
# impossible.
|
||||
#
|
||||
# `golangci-lint config verify` is deliberately NOT run here: it
|
||||
# fetches its JSON schema over a live, unpinned HTTPS call, which would
|
||||
# make linting network-dependent and defeat hash-pinning. The cost of
|
||||
# that: unknown top-level keys in .golangci.yml are silently ignored,
|
||||
# so a mistyped or wrong-schema key lints clean while applying nothing.
|
||||
#
|
||||
# golangci/golangci-lint:v2.12.2 (Debian-based), 2026-08-10
|
||||
FROM golangci/golangci-lint:v2.12.2@sha256:5cceeef04e53efe1470638d4b4b4f5ceefd574955ab3941b2d9a68a8c9ad5240 AS deps
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
# Dependencies first, so this stage stays cached across lint runs.
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Everything below is invalidated on every run by the
|
||||
# --no-cache-filter=lint that script/lint passes: caching is explicitly
|
||||
# waived for linting, and a cached build lints nothing.
|
||||
FROM deps AS lint
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN golangci-lint run --config .golangci.yml ./...
|
||||
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 sneak
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,6 +1,6 @@
|
||||
# dnswatcher
|
||||
|
||||
dnswatcher is an MIT-licensed, pre-1.0 Go daemon by [@sneak](https://sneak.berlin) that monitors DNS records, TCP port availability, and TLS certificates, delivering real-time change notifications via Slack, Mattermost, and ntfy webhooks.
|
||||
dnswatcher is a pre-1.0 Go daemon by [@sneak](https://sneak.berlin) that monitors DNS records, TCP port availability, and TLS certificates, delivering real-time change notifications via Slack, Mattermost, and ntfy webhooks.
|
||||
|
||||
> ⚠️ Pre-1.0 software. APIs, configuration, and behavior may change without notice.
|
||||
|
||||
@@ -380,31 +380,23 @@ standard: normalized scripts in `script/` are the entrypoints for the
|
||||
development workflow, and the Makefile targets are thin shims that call
|
||||
them. We provide:
|
||||
|
||||
- `script/bootstrap` — install all dependencies (go, pinned goimports,
|
||||
`go mod download`). It does not install golangci-lint: see
|
||||
`script/lint` below.
|
||||
- `script/bootstrap` — install all dependencies (go, pinned
|
||||
golangci-lint and goimports, `go mod download`)
|
||||
- `script/setup` — make a fresh clone ready for development: bootstrap
|
||||
plus the git pre-commit hook
|
||||
- `script/projectname` — print the project name (used for the Docker
|
||||
image tag)
|
||||
- `script/test` — run the test suite (race detector, coverage). Caching
|
||||
is waived for testing, exactly as it is for linting: `-count=1`
|
||||
forces every invocation to execute, because the suite queries live
|
||||
DNS and a cached pass queries nothing. Failures are rerun with `-v`
|
||||
automatically, and the build fails even if that rerun passes.
|
||||
- `script/lint` — run golangci-lint, always inside Docker: it builds
|
||||
`Dockerfile.lint`, which COPYs the repo into the digest-pinned
|
||||
`golangci-lint` image and lints as a build step, so a successful
|
||||
build is a clean lint. The linter is never installed or run on the
|
||||
host, and Docker is the only prerequisite. Caching is waived for
|
||||
linting: the lint stage is forced to execute on every run with
|
||||
`--no-cache-filter`, because a cached build lints nothing.
|
||||
- `script/test` — run the test suite (race detector, coverage)
|
||||
- `script/lint` — run golangci-lint
|
||||
- `script/fmt` — format all code (gofmt -s, goimports)
|
||||
- `script/fmt-check` — check formatting (read-only)
|
||||
- `script/check` — run test, lint, and fmt-check
|
||||
- `script/docker` — build the Docker image tagged via
|
||||
`script/projectname`
|
||||
- `script/cibuild` — CI entrypoint: plain `docker build .`
|
||||
- `script/cibuild` — CI entrypoint: `docker build .` with a fresh
|
||||
`CHECK_EPOCH` build argument, so the Dockerfile's `make check` layer
|
||||
is never served from the cache and a green build always means the
|
||||
checks ran on this invocation
|
||||
- `script/precommit` — run by the git pre-commit hook; `go mod tidy`
|
||||
guard, then `script/check`
|
||||
- `script/install-precommit` — install the git pre-commit hook
|
||||
@@ -414,7 +406,7 @@ them. We provide:
|
||||
```sh
|
||||
make build # Build binary to bin/dnswatcher
|
||||
make test # Run tests with race detector
|
||||
make lint # Run golangci-lint in Docker (requires docker)
|
||||
make lint # Run golangci-lint
|
||||
make fmt # Format code
|
||||
make check # Run all checks (test, lint, fmt-check)
|
||||
make clean # Remove build artifacts
|
||||
@@ -486,9 +478,8 @@ Viper for configuration.
|
||||
|
||||
## License
|
||||
|
||||
dnswatcher is released under the MIT License, Copyright (c) 2026
|
||||
[@sneak](https://sneak.berlin). See the [`LICENSE`](./LICENSE) file in the
|
||||
repository root for the full text.
|
||||
License has not yet been chosen for this project. Pending decision by the
|
||||
author (MIT, GPL, or WTFPL).
|
||||
|
||||
## Author
|
||||
|
||||
|
||||
+6
-14
@@ -1,6 +1,6 @@
|
||||
---
|
||||
title: Repository Policies
|
||||
last_modified: 2026-08-07
|
||||
last_modified: 2026-07-06
|
||||
---
|
||||
|
||||
This document covers repository structure, tooling, and workflow standards. Code
|
||||
@@ -189,13 +189,8 @@ style conventions are in separate documents:
|
||||
module under test to verify it compiles/parses. There is no excuse for
|
||||
`make test` to be a no-op.
|
||||
|
||||
- `make test` must complete in under 60 seconds. That is the hard cap, and a
|
||||
suite that exceeds it fails. Under 20 seconds is the target. A suite between
|
||||
20 and 60 seconds is still green, but the overage must be filed as an
|
||||
improvement bug against that repo. Add a 90-second timeout to the test
|
||||
invocation in the Makefile (`go test -timeout 90s`). The backstop deliberately
|
||||
sits above the hard cap so that it catches a genuinely hung test rather than a
|
||||
merely slow one.
|
||||
- `make test` must complete in under 20 seconds. Add a 30-second timeout in the
|
||||
Makefile.
|
||||
|
||||
- **`make test` should use the conditional verbose rerun pattern.** Run tests
|
||||
without `-v` (verbose) first. If tests fail, automatically rerun with `-v` to
|
||||
@@ -214,9 +209,9 @@ style conventions are in separate documents:
|
||||
|
||||
```makefile
|
||||
test:
|
||||
@go test -timeout 90s -race -cover ./... || \
|
||||
@go test -timeout 30s -race -cover ./... || \
|
||||
{ echo "--- Rerunning with -v for details ---"; \
|
||||
go test -timeout 90s -race -v ./...; exit 1; }
|
||||
go test -timeout 30s -race -v ./...; exit 1; }
|
||||
```
|
||||
|
||||
Python example:
|
||||
@@ -265,10 +260,7 @@ style conventions are in separate documents:
|
||||
|
||||
- `.golangci.yml` is standardized and must _NEVER_ be modified by an agent, only
|
||||
manually by the user. Fetch from
|
||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.golangci.yml`. The
|
||||
canonical golangci-lint version is v2.12.2 (released 2026-05-06), installed
|
||||
commit-pinned via
|
||||
`go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5`.
|
||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/.golangci.yml`.
|
||||
|
||||
- When pinning images or packages by hash, add a comment above the reference
|
||||
with the version and date (YYYY-MM-DD).
|
||||
|
||||
+5
-62
@@ -2,10 +2,8 @@
|
||||
|
||||
## DNS Resolution Tests
|
||||
|
||||
All tests that involve DNS resolution — in every package, including
|
||||
consumers of the resolver such as the watcher — **MUST** use live
|
||||
queries against real DNS servers. No mocking, faking, or stubbing of
|
||||
DNS at any layer is permitted.
|
||||
All resolver tests **MUST** use live queries against real DNS servers.
|
||||
No mocking of the DNS client layer is permitted.
|
||||
|
||||
### Rationale
|
||||
|
||||
@@ -14,78 +12,23 @@ the full delegation chain. Mocked responses cannot faithfully represent
|
||||
the variety of real-world DNS behavior (truncation, referrals, glue
|
||||
records, DNSSEC, varied response times, EDNS, etc.). Testing against
|
||||
real servers ensures the resolver works correctly in production.
|
||||
Robustness comes from handling real-world DNS behavior with tolerant
|
||||
assertions and sensible timeouts, not from mocks.
|
||||
|
||||
### Constraints
|
||||
|
||||
- Tests hit real DNS infrastructure and require network access
|
||||
- Test duration depends on network conditions; timeout tuning keeps
|
||||
the suite within the 60-second target
|
||||
the suite within the 30-second target
|
||||
- Query timeout is calibrated to 3× maximum antipodal RTT (~300ms)
|
||||
plus processing margin
|
||||
- Root server fan-out is limited to reduce parallel query load
|
||||
- Flaky failures from transient network issues are acceptable and
|
||||
should be investigated as potential resolver bugs, not papered over
|
||||
with mocks or skip flags
|
||||
- Watcher change-detection tests seed a synthetic *previous state*
|
||||
and compare it against fresh live lookups; the DNS side is never
|
||||
faked
|
||||
- Live query concurrency is bounded per package (`liveGate` in
|
||||
`internal/resolver`, `liveWatcherGate` in `internal/watcher`) so
|
||||
parallel tests do not burst at the root servers
|
||||
- Those gates are package-scoped and therefore per test binary, so
|
||||
`script/test` also passes `-p 1`: with both live-DNS packages
|
||||
running at once the gates sum instead of holding, and the resolver's
|
||||
per-attempt deadlines start expiring
|
||||
|
||||
### Transport failures: loopback nameservers, not mocks
|
||||
|
||||
The resolver classifies a nameserver that stays silent as
|
||||
`StatusTimeout` and one that answers SERVFAIL as `StatusError`. The
|
||||
public network cannot be made to produce either on demand — a
|
||||
black-holed address is only black-holed on some networks, and build
|
||||
environments that transparently intercept UDP/53 answer it locally —
|
||||
so a test built on a chosen remote address asserts on the network it
|
||||
happens to run on rather than on the resolver.
|
||||
|
||||
`internal/resolver/transport_test.go` binds a real nameserver on
|
||||
`127.0.0.1` instead and points the query at it.
|
||||
`nameserverAddr` dials an address that already carries a port as
|
||||
written, so no production behaviour is bypassed to arrange this.
|
||||
|
||||
**This is permitted, and it is not a mock.** The rule above bans
|
||||
substituting `DNSClient` or any other DNS abstraction, which lets the
|
||||
code under test skip DNS and hands it a manufactured verdict. A
|
||||
loopback nameserver does the opposite: the resolver dials a real
|
||||
socket, writes a real query with the real `miekg/dns` client, and
|
||||
applies its real deadline and its real classification logic to what
|
||||
comes back. Choosing which nameserver a live query is sent to is not
|
||||
faking DNS — the resolver is aimed at a nameserver of the caller's
|
||||
choosing in production too.
|
||||
|
||||
The distinction to hold on to: **substituting the client is banned;
|
||||
choosing the server is not.** A test that reaches for a fake
|
||||
`DNSClient` to force a classification is still forbidden, no matter
|
||||
how awkward the alternative looks.
|
||||
|
||||
Such a test must stay cheap. The resolver asks for eight record
|
||||
types and retries each once, so a nameserver silent on every type
|
||||
costs sixteen query timeouts. `TestQueryNameserverIP_Timeout` is
|
||||
silent on `A` alone and answers the rest, which is all the resolver
|
||||
needs to classify the response and keeps the test to two.
|
||||
|
||||
### What NOT to do
|
||||
|
||||
- **Do not mock `DNSClient`**, the watcher's `DNSResolver` interface,
|
||||
or any other DNS abstraction — in any package, for any reason
|
||||
- **Do not mock `DNSClient`** for resolver tests (the mock constructor
|
||||
exists for unit-testing other packages that consume the resolver)
|
||||
- **Do not add `-short` flags** to skip slow tests
|
||||
- **Do not increase `-timeout`** to hide hanging queries
|
||||
- **Do not remove `-count=1` from `script/test`** — Go's test cache
|
||||
replays a previous run's output without querying anything, so a
|
||||
cached pass is not evidence that live resolution works
|
||||
- **Do not remove `-p 1` from `script/test`** — running the live-DNS
|
||||
packages in parallel oversubscribes live DNS past what their gates
|
||||
bound, which surfaces as unrelated resolver tests failing on
|
||||
expired deadlines
|
||||
- **Do not modify linter configuration** to suppress findings
|
||||
|
||||
@@ -14,107 +14,27 @@ pre-1.0. No git tags. Core resolver work in flight on feature/resolver
|
||||
(dirty: internal/resolver/resolver_test.go). Local checkout has diverged
|
||||
from origin: origin/main is 8 commits ahead (watcher orchestrator,
|
||||
unified TARGETS) and origin/feature/resolver already contains the full
|
||||
iterative resolver implementation. DNS mocking is banned in this repo
|
||||
(see `TESTING.md`): all tests use live DNS only. The hermetic mocked
|
||||
tests previously noted on `feature/resolver` are gone from its current
|
||||
tip, which carries a live-DNS suite against `*.dns.sneak.cloud`.
|
||||
iterative resolver implementation with hermetic mocked tests.
|
||||
|
||||
# Next Step
|
||||
|
||||
Add the README sections required by policy (Description, Getting Started,
|
||||
Rationale, Design, TODO, License, Author) if any are still missing.
|
||||
Policy scaffold commit: add LICENSE, REPO_POLICIES.md, .editorconfig,
|
||||
.dockerignore, and .gitea/workflows/check.yml, and add the missing
|
||||
fmt-check, docker, and hooks targets to the Makefile. One commit, then
|
||||
confirm make check still passes.
|
||||
|
||||
# Completed Steps
|
||||
|
||||
- 2026-09-03: restored the transport-failure classification coverage
|
||||
the DNS-mock removal had dropped, and tightened two over-tolerant
|
||||
watcher assertions. `internal/resolver/transport_test.go` covers
|
||||
`StatusTimeout`, `StatusError` and the connection-refused path by
|
||||
binding real nameservers on loopback rather than by mocking
|
||||
`DNSClient` or by aiming a query at a remote address and hoping the
|
||||
network black-holes it; `queryDNS` now honours a port already
|
||||
present in a nameserver address, which is what lets a query be
|
||||
aimed at one. The watcher's `assertStatePopulated` and
|
||||
`TestDomainPortAndTLSChecks` now assert that port and certificate
|
||||
state, and the arguments the port and TLS checkers were called
|
||||
with, match the addresses live DNS returned — previously they
|
||||
asserted only that those sets were non-empty, which would not have
|
||||
caught resolving the wrong addresses. `TESTING.md` records why a
|
||||
loopback nameserver is not a mock.
|
||||
|
||||
- 2026-08-10: comment-only corrections to `script/bootstrap`,
|
||||
`script/cibuild`, and `Dockerfile.lint`. The `goimports` pin in
|
||||
`script/bootstrap` was justified by a claim that `script/fmt-check`
|
||||
runs it on the host; it does not (it runs `gofmt -l .` only), so the
|
||||
header now credits `script/fmt` alone. `script/cibuild` still claimed
|
||||
the `Dockerfile` runs `make check`, which stopped being true when
|
||||
linting moved to its own stage; it now describes the lint stage
|
||||
(`make fmt-check` plus `golangci-lint`) and the builder stage
|
||||
(`make test`, `make build`). The `docker`-missing warning in
|
||||
`script/bootstrap` reads as one sentence instead of three fragments
|
||||
each re-prefixed with `bootstrap:`. `Dockerfile.lint` now records the
|
||||
residual risk of omitting `golangci-lint config verify`: unknown
|
||||
top-level keys in `.golangci.yml` are silently ignored, so a mistyped
|
||||
key lints clean while applying nothing. No behaviour changed
|
||||
- 2026-08-10: MIT `LICENSE` added at the repository root, closing the
|
||||
last gap in `REPO_POLICIES.md`'s required-minimum file list and
|
||||
removing the all-rights-reserved default that would otherwise have
|
||||
shipped with a 1.0 tag. The licence choice is the standing org policy
|
||||
(any public repo lacking a licence gets MIT; a private repo with no
|
||||
licence is already all-rights-reserved), and this repo is public. The
|
||||
file holds the canonical MIT text byte-for-byte with only the
|
||||
copyright line filled in (`Copyright (c) 2026 sneak`); no clauses were
|
||||
added, removed, or reflowed. `README.md`'s first line now names the
|
||||
licence, as the Description requirement demands, and the License
|
||||
section states MIT and points at the file instead of saying the choice
|
||||
is pending. `make fmt` covers only Go sources (`gofmt -s`,
|
||||
`goimports`), so it cannot reflow `LICENSE`
|
||||
- 2026-08-10: the policy scaffold (`REPO_POLICIES.md`, `.editorconfig`,
|
||||
`.dockerignore`, `.gitea/workflows/check.yml`, and the `fmt-check`,
|
||||
`docker`, and hooks Makefile targets) is present; it landed piecemeal
|
||||
across the scripts-to-rule-them-all and policy commits rather than as
|
||||
the single commit this file once planned
|
||||
- 2026-08-10: Go's test cache disabled for `script/test` via `-count=1`,
|
||||
so every invocation actually executes. A cached pass replays an
|
||||
earlier run's output without querying DNS at all, which in this repo
|
||||
means the suite's entire premise goes unexercised while the run
|
||||
reports green in under a second. The conditional verbose rerun that
|
||||
`REPO_POLICIES.md` mandates was added at the same time (the primary
|
||||
run had been unconditionally `-v`): quiet first, `-v` only on
|
||||
failure, `-count=1` on both, and exit 1 forced regardless of the
|
||||
rerun's result so a flake passing the second time cannot turn the
|
||||
build green. `-timeout 90s` left alone as the deliberate backstop
|
||||
above the 60s hard cap. Uncached suite runs ~4s, well inside the 20s
|
||||
target
|
||||
- 2026-08-10: live-DNS test flakiness addressed by robustness rather
|
||||
than gating, per the owner's ruling on #93: new
|
||||
`internal/resolver/livedns_test.go` adds a package-wide concurrency
|
||||
gate (so parallel tests stop bursting at the first root server),
|
||||
retry with exponential backoff on transport failures only, and
|
||||
quorum instead of unanimity for multi-nameserver assertions. Quorum
|
||||
tolerates silence only: every per-nameserver status must be in a
|
||||
closed allowlist (`ok`/`timeout`/`error`, or
|
||||
`nxdomain`/`timeout`/`error`), so a wrong answer from a minority —
|
||||
`nodata` today, any status added later — fails the test instead of
|
||||
sliding through under the majority. The
|
||||
`make test` cap moved to the new org-wide 60s hard cap / 20s target
|
||||
with a 90s `-timeout` backstop; `REPO_POLICIES.md` re-vendored
|
||||
byte-identical from `sneak/prompts`. No mocks, no `-short`, no build
|
||||
tags, no skips, and no change to production resolver behaviour
|
||||
- 2026-08-10: all linting moved into Docker: new root `Dockerfile.lint`
|
||||
on the digest-pinned `golangci/golangci-lint:v2.12.2` image,
|
||||
`script/lint` reduced to a thin wrapper that builds it with
|
||||
`--no-cache-filter=lint` so the linter actually executes every run,
|
||||
golangci-lint install dropped from `script/bootstrap` (goimports
|
||||
stays, `script/fmt` needs it on the host), and the root `Dockerfile`
|
||||
given its own lint stage so its build no longer recurses through
|
||||
`make check` into `script/lint`. `golangci-lint config verify` is
|
||||
deliberately omitted: it fetches its schema over an unpinned live
|
||||
HTTPS call
|
||||
- 2026-08-07: DNS mocking removed from the entire test suite; watcher
|
||||
tests now drive the real iterative resolver against live DNS and
|
||||
`TESTING.md` bans DNS mocks in every package (`remove-dns-mocking`
|
||||
branch)
|
||||
- 2026-08-09: `script/cibuild` can no longer report a green it did not
|
||||
earn. The Dockerfile declares `ARG CHECK_EPOCH` immediately above the
|
||||
check step and expands it into the `RUN` command, and `script/cibuild`
|
||||
passes a fresh `$(date +%s%N)` per invocation, so the `make check`
|
||||
layer is always re-executed while the pinned toolchain install and
|
||||
`go mod download` stay cached. Verified by experiment: before the fix
|
||||
a second run on an unchanged tree returned in 283 ms with the check
|
||||
layer `CACHED`; after it the check runs every time, and a deliberately
|
||||
planted always-failing test made the build fail with exactly that
|
||||
test's message
|
||||
- 2026-08-07: golangci-lint bumped to v2.12.2 (commit-pinned installs
|
||||
in `Dockerfile` and `script/bootstrap`); `.golangci.yml` set to the
|
||||
org-standard v2-schema config used across the org's repos
|
||||
@@ -126,8 +46,7 @@ Rationale, Design, TODO, License, Author) if any are still missing.
|
||||
- 2026-07-07 Adopted scripts-to-rule-them-all: `script/` entrypoints,
|
||||
Makefile shims, README Entrypoints section
|
||||
- 2026-02-20: iterative DNS resolver implemented; tests made hermetic
|
||||
with mocked DNS (origin/feature/resolver, unmerged; superseded — DNS
|
||||
mocking is banned, see `TESTING.md`)
|
||||
with mocked DNS (origin/feature/resolver, unmerged)
|
||||
- 2026-02-20: CI actions and go install refs pinned to commit SHAs;
|
||||
Gitea Actions workflow for make check (origin/ci/make-check, unmerged)
|
||||
- 2026-02-20: watcher monitoring orchestrator merged to main (#8)
|
||||
@@ -144,6 +63,8 @@ Rationale, Design, TODO, License, Author) if any are still missing.
|
||||
|
||||
Compliance:
|
||||
|
||||
- Add README sections required by policy (Description, Getting Started,
|
||||
Rationale, Design, TODO, License, Author) if any are missing
|
||||
- Pin Dockerfile base images by sha256 and ensure the Docker build runs
|
||||
make check
|
||||
|
||||
@@ -152,9 +73,8 @@ Branch reconciliation:
|
||||
- Sync local checkout with origin: local main is 8 commits behind
|
||||
origin/main; local feature/resolver has diverged from
|
||||
origin/feature/resolver, which already implements the resolver
|
||||
- Merge in-flight branches to main once green: feature/resolver
|
||||
(confirm its tests remain live-DNS — DNS mocking is banned, see
|
||||
`TESTING.md`), ci/make-check, feature/portcheck-implementation,
|
||||
- Merge in-flight branches to main once green: feature/resolver,
|
||||
ci/make-check, feature/portcheck-implementation,
|
||||
feature/tlscheck-implementation
|
||||
|
||||
Resolver (plan from untracked TODO.md; largely implemented on
|
||||
@@ -238,7 +158,6 @@ Infrastructure notes (from untracked TODO.md):
|
||||
- Module path sneak.berlin/go/dnswatcher differs from the git.eeqj.de
|
||||
remote intentionally; do not "fix" it
|
||||
- Dependencies: github.com/miekg/dns, golang.org/x/net/publicsuffix
|
||||
- Resolver tests originally used live DNS against `*.dns.sneak.cloud`
|
||||
(required records documented in the test file header); `main` now
|
||||
tests against live public DNS. DNS mocking is banned (see
|
||||
`TESTING.md`); never reintroduce hermetic mocked DNS tests
|
||||
- Resolver tests originally used live DNS against *.dns.sneak.cloud
|
||||
(required records documented in the test file header); origin now has
|
||||
mocked hermetic tests, keep them hermetic
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
// DNSClient abstracts DNS wire-protocol exchanges over a single
|
||||
// transport, letting the resolver switch between UDP and TCP.
|
||||
// DNSClient abstracts DNS wire-protocol exchanges so the resolver
|
||||
// can be tested without hitting real nameservers.
|
||||
type DNSClient interface {
|
||||
ExchangeContext(
|
||||
ctx context.Context,
|
||||
|
||||
@@ -20,10 +20,6 @@ const (
|
||||
minDomainLabels = 2
|
||||
)
|
||||
|
||||
// defaultDNSPort is the port a nameserver is assumed to listen on
|
||||
// when its address does not carry one.
|
||||
const defaultDNSPort = "53"
|
||||
|
||||
// ErrRefused is returned when a DNS server refuses a query.
|
||||
var ErrRefused = errors.New("dns query refused")
|
||||
|
||||
@@ -110,19 +106,6 @@ func (r *Resolver) retryTCP(
|
||||
return resp
|
||||
}
|
||||
|
||||
// nameserverAddr renders a nameserver address for dialling. A bare
|
||||
// address — the normal case, and what a delegation's glue records
|
||||
// carry — is given the default DNS port. An address that already
|
||||
// specifies a port is dialled as written, which is what makes a
|
||||
// nameserver listening somewhere other than 53 reachable.
|
||||
func nameserverAddr(nsIP string) string {
|
||||
if _, _, err := net.SplitHostPort(nsIP); err == nil {
|
||||
return nsIP
|
||||
}
|
||||
|
||||
return net.JoinHostPort(nsIP, defaultDNSPort)
|
||||
}
|
||||
|
||||
// queryDNS sends a DNS query to a specific server IP.
|
||||
// Tries non-recursive first, falls back to recursive on
|
||||
// REFUSED (handles DNS interception environments).
|
||||
@@ -137,7 +120,7 @@ func (r *Resolver) queryDNS(
|
||||
}
|
||||
|
||||
name = dns.Fqdn(name)
|
||||
addr := nameserverAddr(serverIP)
|
||||
addr := net.JoinHostPort(serverIP, "53")
|
||||
|
||||
msg := new(dns.Msg)
|
||||
msg.SetQuestion(name, qtype)
|
||||
|
||||
@@ -1,284 +0,0 @@
|
||||
package resolver_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/resolver"
|
||||
)
|
||||
|
||||
// Tests for the live-DNS harness in livedns_test.go itself. These
|
||||
// exercise pure logic and the retry/concurrency plumbing; they
|
||||
// perform no DNS resolution of any kind, so they neither mock DNS
|
||||
// nor depend on it.
|
||||
|
||||
// Names for the synthetic status maps below. Nothing is ever queried
|
||||
// at them: they are map keys handed to the package's pure counting
|
||||
// helpers, not a stand-in for a nameserver.
|
||||
const (
|
||||
nsExample1 = "ns1.example."
|
||||
nsExample2 = "ns2.example."
|
||||
nsExample3 = "ns3.example."
|
||||
nsExample4 = "ns4.example."
|
||||
)
|
||||
|
||||
func TestLiveQuorumIsStrictMajority(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := map[int]int{
|
||||
0: 1,
|
||||
1: 1,
|
||||
2: 2,
|
||||
3: 2,
|
||||
4: 3,
|
||||
5: 3,
|
||||
13: 7,
|
||||
}
|
||||
|
||||
for total, want := range cases {
|
||||
assert.Equal(
|
||||
t, want, liveQuorum(total),
|
||||
"liveQuorum(%d)", total,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatusCountingIgnoresSilentNameservers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
results := map[string]*resolver.NameserverResponse{
|
||||
nsExample1: {
|
||||
Nameserver: nsExample1,
|
||||
Status: resolver.StatusOK,
|
||||
},
|
||||
nsExample2: {
|
||||
Nameserver: nsExample2,
|
||||
Status: resolver.StatusOK,
|
||||
},
|
||||
nsExample3: {
|
||||
Nameserver: nsExample3,
|
||||
Status: resolver.StatusTimeout,
|
||||
},
|
||||
nsExample4: {
|
||||
Nameserver: nsExample4,
|
||||
Status: resolver.StatusError,
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(
|
||||
t, 2, countStatus(results, resolver.StatusOK),
|
||||
)
|
||||
assert.Equal(
|
||||
t, 0, countStatus(results, resolver.StatusNXDomain),
|
||||
)
|
||||
|
||||
// Two of four answered, which is short of the quorum of
|
||||
// three: this is the state that triggers a retry rather
|
||||
// than an assertion failure.
|
||||
assert.Equal(t, 2, answeredCount(results))
|
||||
assert.Less(t, answeredCount(results), liveQuorum(len(results)))
|
||||
|
||||
assert.Equal(
|
||||
t,
|
||||
"ns1.example.=ok ns2.example.=ok "+
|
||||
"ns3.example.=timeout ns4.example.=error",
|
||||
describeStatuses(results),
|
||||
)
|
||||
}
|
||||
|
||||
func TestRetryLiveRecoversFromTransientFailure(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const wantAttempts = 2
|
||||
|
||||
attempts := 0
|
||||
|
||||
retryLive(t, "transient", func(_ context.Context) error {
|
||||
attempts++
|
||||
|
||||
if attempts < wantAttempts {
|
||||
return errLiveNoAnswer
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
assert.Equal(t, wantAttempts, attempts)
|
||||
}
|
||||
|
||||
func TestRetryLiveGivesEachAttemptADeadline(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
retryLive(t, "deadline", func(ctx context.Context) error {
|
||||
deadline, ok := ctx.Deadline()
|
||||
assert.True(t, ok, "attempt should carry a deadline")
|
||||
|
||||
remaining := time.Until(deadline)
|
||||
|
||||
assert.LessOrEqual(t, remaining, liveAttemptTimeout)
|
||||
|
||||
// Lower bound too: without one this passes for a
|
||||
// deadline far shorter than intended, which would
|
||||
// silently turn every live attempt into an instant
|
||||
// timeout.
|
||||
assert.Greater(t, remaining, liveAttemptTimeout/2)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// TestUnsanctionedStatusesRejectsWrongAnswers is the regression test
|
||||
// for the defect this allowlist exists to prevent: a minority of
|
||||
// nameservers answering WRONGLY while quorum keeps the suite green.
|
||||
// nodata is the case that motivated it — it is a wrong answer, not
|
||||
// silence, and it was previously banned by neither test.
|
||||
func TestUnsanctionedStatusesRejectsWrongAnswers(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Four nameservers, three OK and one answering nodata: a
|
||||
// quorum of three is satisfied and no NXDOMAIN is present, so
|
||||
// the old blocklist assertions both passed on this input.
|
||||
results := map[string]*resolver.NameserverResponse{
|
||||
nsExample1: {
|
||||
Nameserver: nsExample1,
|
||||
Status: resolver.StatusOK,
|
||||
},
|
||||
nsExample2: {
|
||||
Nameserver: nsExample2,
|
||||
Status: resolver.StatusOK,
|
||||
},
|
||||
nsExample3: {
|
||||
Nameserver: nsExample3,
|
||||
Status: resolver.StatusOK,
|
||||
},
|
||||
nsExample4: {
|
||||
Nameserver: nsExample4,
|
||||
Status: resolver.StatusNoData,
|
||||
},
|
||||
}
|
||||
|
||||
assert.GreaterOrEqual(
|
||||
t,
|
||||
countStatus(results, resolver.StatusOK),
|
||||
liveQuorum(len(results)),
|
||||
)
|
||||
assert.Zero(t, countStatus(results, resolver.StatusNXDomain))
|
||||
|
||||
// nodata is an ANSWER, so it never triggers a retry: nothing
|
||||
// but the allowlist stands between it and a false green.
|
||||
assert.Equal(t, len(results), answeredCount(results))
|
||||
|
||||
assert.Equal(
|
||||
t,
|
||||
[]string{nsExample4 + "=nodata"},
|
||||
unsanctionedStatuses(
|
||||
results,
|
||||
resolver.StatusOK,
|
||||
resolver.StatusTimeout,
|
||||
resolver.StatusError,
|
||||
),
|
||||
"nodata must be reported as an unsanctioned status",
|
||||
)
|
||||
}
|
||||
|
||||
func TestUnsanctionedStatusesToleratesSilenceOnly(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
results := map[string]*resolver.NameserverResponse{
|
||||
nsExample1: {
|
||||
Nameserver: nsExample1,
|
||||
Status: resolver.StatusNXDomain,
|
||||
},
|
||||
nsExample2: {
|
||||
Nameserver: nsExample2,
|
||||
Status: resolver.StatusTimeout,
|
||||
},
|
||||
nsExample3: {
|
||||
Nameserver: nsExample3,
|
||||
Status: resolver.StatusError,
|
||||
},
|
||||
}
|
||||
|
||||
allowed := []string{
|
||||
resolver.StatusNXDomain,
|
||||
resolver.StatusTimeout,
|
||||
resolver.StatusError,
|
||||
}
|
||||
|
||||
assert.Empty(
|
||||
t,
|
||||
unsanctionedStatuses(results, allowed...),
|
||||
"timeout and error are non-answers and are tolerated",
|
||||
)
|
||||
|
||||
// The same silent nameservers do not count towards a quorum.
|
||||
assert.Equal(t, 1, answeredCount(results))
|
||||
|
||||
// An unknown status is treated as silence by answeredCount —
|
||||
// so it retries and fails loudly — and is unsanctioned by the
|
||||
// allowlist rather than quietly permitted.
|
||||
const laterStatus = "some-status-added-later"
|
||||
|
||||
results[nsExample4] = &resolver.NameserverResponse{
|
||||
Nameserver: nsExample4,
|
||||
Status: laterStatus,
|
||||
}
|
||||
|
||||
assert.Equal(t, 1, answeredCount(results))
|
||||
assert.Equal(
|
||||
t,
|
||||
[]string{nsExample4 + "=" + laterStatus},
|
||||
unsanctionedStatuses(results, allowed...),
|
||||
)
|
||||
}
|
||||
|
||||
func TestRunLiveBoundsConcurrency(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const workers = 24
|
||||
|
||||
var (
|
||||
mu sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
inFlight int
|
||||
maxSeen int
|
||||
)
|
||||
|
||||
wg.Add(workers)
|
||||
|
||||
for range workers {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
_ = runLive(func(_ context.Context) error {
|
||||
mu.Lock()
|
||||
inFlight++
|
||||
|
||||
if inFlight > maxSeen {
|
||||
maxSeen = inFlight
|
||||
}
|
||||
mu.Unlock()
|
||||
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
mu.Lock()
|
||||
inFlight--
|
||||
mu.Unlock()
|
||||
|
||||
return nil
|
||||
})
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
assert.Positive(t, maxSeen)
|
||||
assert.LessOrEqual(
|
||||
t, maxSeen, liveConcurrency,
|
||||
"live queries must stay under the package-wide gate",
|
||||
)
|
||||
}
|
||||
@@ -1,495 +0,0 @@
|
||||
package resolver_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/resolver"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Live DNS test support
|
||||
// ----------------------------------------------------------------
|
||||
//
|
||||
// Every test in this package resolves against the real, live DNS —
|
||||
// see TESTING.md. Nothing here mocks, fakes, stubs, records or
|
||||
// replays DNS, and nothing here skips or gates a test: the helpers
|
||||
// below only change *how* the live queries are issued, so that a
|
||||
// single dropped UDP packet or one slow authoritative server does
|
||||
// not turn a correct resolver into a red build.
|
||||
//
|
||||
// Three mechanisms, all test-side:
|
||||
//
|
||||
// 1. Bounded concurrency. The package's tests are parallel and the
|
||||
// build hosts have many cores, so without a limit every test
|
||||
// starts its own iterative resolution at the same instant and
|
||||
// they all hit the first root server in rootServerList() within
|
||||
// a few milliseconds of each other. Root servers rate-limit
|
||||
// that, which shows up as a different arbitrary subset of tests
|
||||
// failing on each run. liveGate caps how many resolutions are
|
||||
// in flight at once.
|
||||
//
|
||||
// 2. Retry with exponential backoff. Each live operation gets
|
||||
// several attempts with its own timeout. The retry predicate is
|
||||
// strictly transport-level — "did a nameserver answer at all" —
|
||||
// never the assertion the test is making. A resolver that
|
||||
// answers incorrectly still fails on the first attempt.
|
||||
//
|
||||
// 3. Quorum. Where an assertion spans several independent
|
||||
// nameservers, a strict majority answering as expected is
|
||||
// enough; a server that fails to answer is tolerated, while a
|
||||
// server that answers *wrongly* still fails the test.
|
||||
//
|
||||
// The tolerance in (3) is expressed as an ALLOWLIST of sanctioned
|
||||
// statuses, never as a blocklist of known-bad ones. A blocklist bans
|
||||
// the one wrong answer its author thought of and silently admits
|
||||
// every other status, including any added to the resolver later; an
|
||||
// allowlist fails on anything nobody explicitly sanctioned. Silence
|
||||
// (timeout, error) is the only thing quorum exists to tolerate. A
|
||||
// *wrong answer* — nxdomain for a name that exists, ok for one that
|
||||
// does not, nodata for either — is never tolerated at any count.
|
||||
|
||||
const (
|
||||
// liveAttempts is how many times a live DNS operation is
|
||||
// attempted before the test fails.
|
||||
liveAttempts = 3
|
||||
|
||||
// liveAttemptTimeout bounds one attempt. Worst case for an
|
||||
// operation is liveAttempts * liveAttemptTimeout plus the
|
||||
// backoff — about 26 seconds, well inside the 90-second
|
||||
// `go test -timeout` backstop even when several operations
|
||||
// exhaust their attempts.
|
||||
liveAttemptTimeout = 8 * time.Second
|
||||
|
||||
// liveBackoffBase is the delay after the first failed
|
||||
// attempt; it is multiplied by liveBackoffFactor each time.
|
||||
liveBackoffBase = 500 * time.Millisecond
|
||||
|
||||
// liveBackoffFactor is the exponential backoff multiplier.
|
||||
liveBackoffFactor = 2
|
||||
|
||||
// liveConcurrency caps how many live resolutions may be in
|
||||
// flight across the whole package at once.
|
||||
liveConcurrency = 6
|
||||
|
||||
// minNameservers is the smallest nameserver count a
|
||||
// well-run zone is expected to publish.
|
||||
minNameservers = 2
|
||||
)
|
||||
|
||||
// liveGate bounds concurrent live resolutions package-wide. It has
|
||||
// to be package scoped: the whole point is that it is shared by
|
||||
// every parallel test in the package.
|
||||
//
|
||||
//nolint:gochecknoglobals // package-wide live query rate limit
|
||||
var liveGate = make(chan struct{}, liveConcurrency)
|
||||
|
||||
var (
|
||||
// errLiveNoAnswer reports that a live operation produced no
|
||||
// usable answer, which is retried rather than asserted on.
|
||||
errLiveNoAnswer = errors.New("no answer from live DNS")
|
||||
|
||||
// errLiveNoQuorum reports that too few of a domain's
|
||||
// nameservers answered for a quorum assertion to be made.
|
||||
errLiveNoQuorum = errors.New("no nameserver quorum")
|
||||
)
|
||||
|
||||
// runLive executes one attempt of a live operation, holding a slot
|
||||
// in liveGate for its duration and bounding it with its own
|
||||
// timeout.
|
||||
func runLive(op func(ctx context.Context) error) error {
|
||||
liveGate <- struct{}{}
|
||||
defer func() { <-liveGate }()
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), liveAttemptTimeout,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
return op(ctx)
|
||||
}
|
||||
|
||||
// retryLive runs op until it reports success, retrying transport
|
||||
// failures with exponential backoff, and fails the test if every
|
||||
// attempt fails. op returns an error only for a failure to obtain
|
||||
// an answer — never for an answer the test disagrees with, which
|
||||
// belongs in an assertion so that it fails immediately. op stores
|
||||
// whatever it obtained where its caller can find it.
|
||||
func retryLive(
|
||||
t *testing.T,
|
||||
what string,
|
||||
op func(ctx context.Context) error,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
var last error
|
||||
|
||||
backoff := liveBackoffBase
|
||||
|
||||
for attempt := range liveAttempts {
|
||||
if attempt > 0 {
|
||||
t.Logf(
|
||||
"%s: attempt %d of %d failed (%v), "+
|
||||
"retrying in %s",
|
||||
what, attempt, liveAttempts, last, backoff,
|
||||
)
|
||||
time.Sleep(backoff)
|
||||
|
||||
backoff *= liveBackoffFactor
|
||||
}
|
||||
|
||||
last = runLive(op)
|
||||
if last == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
t.Fatalf(
|
||||
"%s: no answer after %d live attempts: %v",
|
||||
what, liveAttempts, last,
|
||||
)
|
||||
}
|
||||
|
||||
// liveQuorum is how many of total nameservers must agree for a
|
||||
// multi-nameserver assertion to hold: a strict majority.
|
||||
func liveQuorum(total int) int {
|
||||
if total < 1 {
|
||||
return 1
|
||||
}
|
||||
|
||||
return total/2 + 1
|
||||
}
|
||||
|
||||
// countStatus counts the responses carrying the given status.
|
||||
func countStatus(
|
||||
results map[string]*resolver.NameserverResponse,
|
||||
status string,
|
||||
) int {
|
||||
n := 0
|
||||
|
||||
for _, resp := range results {
|
||||
if resp.Status == status {
|
||||
n++
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// liveAnswerStatuses is the closed set of statuses that count as a
|
||||
// nameserver having ANSWERED at all, whether or not the test agrees
|
||||
// with the answer. It is deliberately an allowlist: a status added
|
||||
// to the resolver later is treated as silence, so it can only ever
|
||||
// cause a retry and then a loud failure, never a quiet pass.
|
||||
func liveAnswerStatuses() []string {
|
||||
return []string{
|
||||
resolver.StatusOK,
|
||||
resolver.StatusNXDomain,
|
||||
resolver.StatusNoData,
|
||||
}
|
||||
}
|
||||
|
||||
// answeredCount counts the nameservers that produced an answer of
|
||||
// any kind, as opposed to failing or timing out.
|
||||
func answeredCount(
|
||||
results map[string]*resolver.NameserverResponse,
|
||||
) int {
|
||||
answers := liveAnswerStatuses()
|
||||
|
||||
n := 0
|
||||
|
||||
for _, resp := range results {
|
||||
if slices.Contains(answers, resp.Status) {
|
||||
n++
|
||||
}
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// unsanctionedStatuses returns "nameserver=status" for every result
|
||||
// whose status the caller did not explicitly sanction, sorted for a
|
||||
// stable failure message. Callers pass the full closed set they will
|
||||
// accept — the expected answer plus whichever non-answers (timeout,
|
||||
// error) quorum is allowed to tolerate — so that any status outside
|
||||
// it fails the test by name.
|
||||
func unsanctionedStatuses(
|
||||
results map[string]*resolver.NameserverResponse,
|
||||
allowed ...string,
|
||||
) []string {
|
||||
offenders := make([]string, 0, len(results))
|
||||
|
||||
for ns, resp := range results {
|
||||
if slices.Contains(allowed, resp.Status) {
|
||||
continue
|
||||
}
|
||||
|
||||
offenders = append(
|
||||
offenders, fmt.Sprintf("%s=%s", ns, resp.Status),
|
||||
)
|
||||
}
|
||||
|
||||
sort.Strings(offenders)
|
||||
|
||||
return offenders
|
||||
}
|
||||
|
||||
// describeStatuses renders per-nameserver statuses for use in
|
||||
// assertion failure messages.
|
||||
func describeStatuses(
|
||||
results map[string]*resolver.NameserverResponse,
|
||||
) string {
|
||||
parts := make([]string, 0, len(results))
|
||||
for ns, resp := range results {
|
||||
parts = append(
|
||||
parts, fmt.Sprintf("%s=%s", ns, resp.Status),
|
||||
)
|
||||
}
|
||||
|
||||
sort.Strings(parts)
|
||||
|
||||
return strings.Join(parts, " ")
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// Live operation wrappers
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
// liveFindAuthoritative resolves a domain's authoritative
|
||||
// nameservers, retrying until the delegation chain can be walked.
|
||||
func liveFindAuthoritative(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
domain string,
|
||||
) []string {
|
||||
t.Helper()
|
||||
|
||||
var out []string
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
"FindAuthoritativeNameservers("+domain+")",
|
||||
func(ctx context.Context) error {
|
||||
ns, err := r.FindAuthoritativeNameservers(ctx, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ns) == 0 {
|
||||
return fmt.Errorf(
|
||||
"%w: %s has no nameservers",
|
||||
errLiveNoAnswer, domain,
|
||||
)
|
||||
}
|
||||
|
||||
out = ns
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// liveLookupNS is liveFindAuthoritative through the LookupNS entry
|
||||
// point, so that both entry points stay independently exercised.
|
||||
func liveLookupNS(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
domain string,
|
||||
) []string {
|
||||
t.Helper()
|
||||
|
||||
var out []string
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
"LookupNS("+domain+")",
|
||||
func(ctx context.Context) error {
|
||||
ns, err := r.LookupNS(ctx, domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ns) == 0 {
|
||||
return fmt.Errorf(
|
||||
"%w: %s has no nameservers",
|
||||
errLiveNoAnswer, domain,
|
||||
)
|
||||
}
|
||||
|
||||
out = ns
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// liveQueryNameserver queries one nameserver, retrying while that
|
||||
// nameserver fails to answer. NXDOMAIN and NODATA are answers and
|
||||
// are returned to the caller to assert on.
|
||||
func liveQueryNameserver(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
nameserver string,
|
||||
hostname string,
|
||||
) *resolver.NameserverResponse {
|
||||
t.Helper()
|
||||
|
||||
what := fmt.Sprintf(
|
||||
"QueryNameserver(%s, %s)", nameserver, hostname,
|
||||
)
|
||||
|
||||
var out *resolver.NameserverResponse
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
what,
|
||||
func(ctx context.Context) error {
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, nameserver, hostname,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if resp.Status == resolver.StatusTimeout ||
|
||||
resp.Status == resolver.StatusError {
|
||||
return fmt.Errorf(
|
||||
"%w: %s returned %s: %s",
|
||||
errLiveNoAnswer, nameserver,
|
||||
resp.Status, resp.Error,
|
||||
)
|
||||
}
|
||||
|
||||
out = resp
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// liveQueryAllNameservers queries every authoritative nameserver
|
||||
// for a hostname, retrying until a quorum of them has answered.
|
||||
// Individual nameservers that stay silent are left in the result
|
||||
// for the caller to account for.
|
||||
func liveQueryAllNameservers(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
hostname string,
|
||||
) map[string]*resolver.NameserverResponse {
|
||||
t.Helper()
|
||||
|
||||
var out map[string]*resolver.NameserverResponse
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
"QueryAllNameservers("+hostname+")",
|
||||
func(ctx context.Context) error {
|
||||
results, err := r.QueryAllNameservers(ctx, hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
return fmt.Errorf(
|
||||
"%w: no nameservers queried for %s",
|
||||
errLiveNoAnswer, hostname,
|
||||
)
|
||||
}
|
||||
|
||||
answered := answeredCount(results)
|
||||
if answered < liveQuorum(len(results)) {
|
||||
return fmt.Errorf(
|
||||
"%w: %d of %d answered: %s",
|
||||
errLiveNoQuorum, answered,
|
||||
len(results), describeStatuses(results),
|
||||
)
|
||||
}
|
||||
|
||||
out = results
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// liveResolveIPs resolves a hostname that is expected to have
|
||||
// addresses, retrying until at least one is returned.
|
||||
func liveResolveIPs(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
hostname string,
|
||||
) []string {
|
||||
t.Helper()
|
||||
|
||||
var out []string
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
"ResolveIPAddresses("+hostname+")",
|
||||
func(ctx context.Context) error {
|
||||
ips, err := r.ResolveIPAddresses(ctx, hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(ips) == 0 {
|
||||
return fmt.Errorf(
|
||||
"%w: no addresses for %s",
|
||||
errLiveNoAnswer, hostname,
|
||||
)
|
||||
}
|
||||
|
||||
out = ips
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// liveResolveIPsAllowingEmpty resolves a hostname that may legitimately
|
||||
// have no addresses, so the empty result is returned rather than
|
||||
// retried. Used for names that must not exist; the corresponding
|
||||
// QueryAllNameservers test is what proves the nameservers actively
|
||||
// said NXDOMAIN rather than merely staying silent.
|
||||
func liveResolveIPsAllowingEmpty(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
hostname string,
|
||||
) []string {
|
||||
t.Helper()
|
||||
|
||||
var out []string
|
||||
|
||||
retryLive(
|
||||
t,
|
||||
"ResolveIPAddresses("+hostname+")",
|
||||
func(ctx context.Context) error {
|
||||
ips, err := r.ResolveIPAddresses(ctx, hostname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
out = ips
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
|
||||
return out
|
||||
}
|
||||
@@ -67,4 +67,17 @@ func NewFromLogger(log *slog.Logger) *Resolver {
|
||||
}
|
||||
}
|
||||
|
||||
// NewFromLoggerWithClient creates a Resolver with a custom DNS
|
||||
// client, useful for testing with mock DNS responses.
|
||||
func NewFromLoggerWithClient(
|
||||
log *slog.Logger,
|
||||
client DNSClient,
|
||||
) *Resolver {
|
||||
return &Resolver{
|
||||
log: log,
|
||||
client: client,
|
||||
tcp: client,
|
||||
}
|
||||
}
|
||||
|
||||
// Method implementations are in iterative.go.
|
||||
|
||||
+256
-101
@@ -8,7 +8,9 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -30,17 +32,32 @@ func newTestResolver(t *testing.T) *resolver.Resolver {
|
||||
return resolver.NewFromLogger(log)
|
||||
}
|
||||
|
||||
// findOneNSForDomain picks one authoritative nameserver to aim a
|
||||
// test at. Live-DNS retry, concurrency and quorum handling live in
|
||||
// livedns_test.go.
|
||||
func testContext(t *testing.T) context.Context {
|
||||
t.Helper()
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), 60*time.Second,
|
||||
)
|
||||
t.Cleanup(cancel)
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
func findOneNSForDomain(
|
||||
t *testing.T,
|
||||
r *resolver.Resolver,
|
||||
ctx context.Context, //nolint:revive // test helper
|
||||
domain string,
|
||||
) string {
|
||||
t.Helper()
|
||||
|
||||
return liveFindAuthoritative(t, r, domain)[0]
|
||||
nameservers, err := r.FindAuthoritativeNameservers(
|
||||
ctx, domain,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, nameservers)
|
||||
|
||||
return nameservers[0]
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@@ -53,7 +70,13 @@ func TestFindAuthoritativeNameservers_ValidDomain(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveFindAuthoritative(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
nameservers, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, nameservers)
|
||||
|
||||
hasGoogleNS := false
|
||||
|
||||
@@ -76,9 +99,13 @@ func TestFindAuthoritativeNameservers_Subdomain(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveFindAuthoritative(t, r, "www.google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
assert.NotEmpty(t, nameservers)
|
||||
nameservers, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "www.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, nameservers)
|
||||
}
|
||||
|
||||
func TestFindAuthoritativeNameservers_ReturnsSorted(
|
||||
@@ -87,7 +114,12 @@ func TestFindAuthoritativeNameservers_ReturnsSorted(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveFindAuthoritative(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
nameservers, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(
|
||||
t,
|
||||
@@ -102,8 +134,17 @@ func TestFindAuthoritativeNameservers_Deterministic(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
first := liveFindAuthoritative(t, r, "google.com")
|
||||
second := liveFindAuthoritative(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
first, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
second, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, first, second)
|
||||
}
|
||||
@@ -114,8 +155,17 @@ func TestFindAuthoritativeNameservers_TrailingDot(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns1 := liveFindAuthoritative(t, r, "google.com")
|
||||
ns2 := liveFindAuthoritative(t, r, "google.com.")
|
||||
ctx := testContext(t)
|
||||
|
||||
ns1, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
ns2, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com.",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, ns1, ns2)
|
||||
}
|
||||
@@ -126,7 +176,13 @@ func TestFindAuthoritativeNameservers_CloudflareDomain(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveFindAuthoritative(t, r, "cloudflare.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
nameservers, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "cloudflare.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, nameservers)
|
||||
|
||||
for _, ns := range nameservers {
|
||||
assert.True(t, strings.HasSuffix(ns, "."),
|
||||
@@ -143,9 +199,13 @@ func TestQueryNameserver_BasicA(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "www.google.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "www.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
|
||||
assert.Equal(t, resolver.StatusOK, resp.Status)
|
||||
@@ -162,8 +222,13 @@ func TestQueryNameserver_AAAA(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "cloudflare.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "cloudflare.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "cloudflare.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "cloudflare.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
aaaaRecords := resp.Records["AAAA"]
|
||||
require.NotEmpty(t, aaaaRecords,
|
||||
@@ -182,8 +247,13 @@ func TestQueryNameserver_MX(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "google.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
mxRecords := resp.Records["MX"]
|
||||
require.NotEmpty(t, mxRecords,
|
||||
@@ -195,8 +265,13 @@ func TestQueryNameserver_TXT(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "google.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
txtRecords := resp.Records["TXT"]
|
||||
require.NotEmpty(t, txtRecords,
|
||||
@@ -222,10 +297,14 @@ func TestQueryNameserver_NXDomain(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(
|
||||
t, r, ns, "this-surely-does-not-exist-xyz.google.com",
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns,
|
||||
"this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, resolver.StatusNXDomain, resp.Status)
|
||||
}
|
||||
@@ -234,8 +313,13 @@ func TestQueryNameserver_RecordsSorted(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "google.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
for recordType, values := range resp.Records {
|
||||
assert.True(
|
||||
@@ -252,8 +336,13 @@ func TestQueryNameserver_ResponseIncludesNameserver(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "cloudflare.com")
|
||||
resp := liveQueryNameserver(t, r, ns, "cloudflare.com")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "cloudflare.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns, "cloudflare.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, ns, resp.Nameserver)
|
||||
}
|
||||
@@ -264,10 +353,14 @@ func TestQueryNameserver_EmptyRecordsOnNXDomain(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp := liveQueryNameserver(
|
||||
t, r, ns, "this-surely-does-not-exist-xyz.google.com",
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp, err := r.QueryNameserver(
|
||||
ctx, ns,
|
||||
"this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
totalRecords := 0
|
||||
for _, values := range resp.Records {
|
||||
@@ -281,9 +374,18 @@ func TestQueryNameserver_TrailingDotHandling(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ns := findOneNSForDomain(t, r, "google.com")
|
||||
resp1 := liveQueryNameserver(t, r, ns, "google.com")
|
||||
resp2 := liveQueryNameserver(t, r, ns, "google.com.")
|
||||
ctx := testContext(t)
|
||||
ns := findOneNSForDomain(t, r, ctx, "google.com")
|
||||
|
||||
resp1, err := r.QueryNameserver(
|
||||
ctx, ns, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
resp2, err := r.QueryNameserver(
|
||||
ctx, ns, "google.com.",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, resp1.Status, resp2.Status)
|
||||
}
|
||||
@@ -296,9 +398,15 @@ func TestQueryAllNameservers_ReturnsAllNS(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
results := liveQueryAllNameservers(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
assert.GreaterOrEqual(t, len(results), minNameservers)
|
||||
results, err := r.QueryAllNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, results)
|
||||
|
||||
assert.GreaterOrEqual(t, len(results), 2)
|
||||
|
||||
for ns, resp := range results {
|
||||
assert.Equal(t, ns, resp.Nameserver)
|
||||
@@ -309,36 +417,19 @@ func TestQueryAllNameservers_AllReturnOK(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
results := liveQueryAllNameservers(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
// A quorum, not unanimity: one authoritative server being
|
||||
// slow or rate-limiting us is a property of the live
|
||||
// internet, not a resolver defect.
|
||||
assert.GreaterOrEqual(
|
||||
t,
|
||||
countStatus(results, resolver.StatusOK),
|
||||
liveQuorum(len(results)),
|
||||
"a quorum of nameservers should answer OK: %s",
|
||||
describeStatuses(results),
|
||||
results, err := r.QueryAllNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Quorum tolerates SILENCE only. Every individual result must
|
||||
// be either the expected answer or a non-answer: ok, timeout
|
||||
// or error, and nothing else. Stated as a closed allowlist so
|
||||
// that a wrong answer no one thought to ban — nxdomain and
|
||||
// nodata today, any status added later — fails here rather
|
||||
// than sliding through under the quorum.
|
||||
assert.Empty(
|
||||
t,
|
||||
unsanctionedStatuses(
|
||||
results,
|
||||
resolver.StatusOK,
|
||||
resolver.StatusTimeout,
|
||||
resolver.StatusError,
|
||||
),
|
||||
"every nameserver must answer OK or not answer at all: %s",
|
||||
describeStatuses(results),
|
||||
for ns, resp := range results {
|
||||
assert.Equal(
|
||||
t, resolver.StatusOK, resp.Status,
|
||||
"NS %s should return OK", ns,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryAllNameservers_NXDomainFromAllNS(
|
||||
@@ -347,34 +438,20 @@ func TestQueryAllNameservers_NXDomainFromAllNS(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
results := liveQueryAllNameservers(
|
||||
t, r, "this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
ctx := testContext(t)
|
||||
|
||||
assert.GreaterOrEqual(
|
||||
t,
|
||||
countStatus(results, resolver.StatusNXDomain),
|
||||
liveQuorum(len(results)),
|
||||
"a quorum of nameservers should report NXDOMAIN: %s",
|
||||
describeStatuses(results),
|
||||
results, err := r.QueryAllNameservers(
|
||||
ctx,
|
||||
"this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Silence is tolerated; any actual answer other than NXDOMAIN
|
||||
// is not. Closed allowlist for the same reason as above: a
|
||||
// server answering `ok` or `nodata` for a name that must not
|
||||
// exist is a wrong answer, not a slow one.
|
||||
assert.Empty(
|
||||
t,
|
||||
unsanctionedStatuses(
|
||||
results,
|
||||
resolver.StatusNXDomain,
|
||||
resolver.StatusTimeout,
|
||||
resolver.StatusError,
|
||||
),
|
||||
"every nameserver must report NXDOMAIN or not answer "+
|
||||
"at all: %s",
|
||||
describeStatuses(results),
|
||||
for ns, resp := range results {
|
||||
assert.Equal(
|
||||
t, resolver.StatusNXDomain, resp.Status,
|
||||
"NS %s should return nxdomain", ns,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@@ -385,7 +462,11 @@ func TestLookupNS_ValidDomain(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveLookupNS(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
nameservers, err := r.LookupNS(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, nameservers)
|
||||
|
||||
for _, ns := range nameservers {
|
||||
assert.True(t, strings.HasSuffix(ns, "."),
|
||||
@@ -398,7 +479,10 @@ func TestLookupNS_Sorted(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
nameservers := liveLookupNS(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
nameservers, err := r.LookupNS(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, sort.StringsAreSorted(nameservers))
|
||||
}
|
||||
@@ -407,8 +491,15 @@ func TestLookupNS_MatchesFindAuthoritative(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
fromLookup := liveLookupNS(t, r, "google.com")
|
||||
fromFind := liveFindAuthoritative(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
fromLookup, err := r.LookupNS(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
|
||||
fromFind, err := r.FindAuthoritativeNameservers(
|
||||
ctx, "google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, fromFind, fromLookup)
|
||||
}
|
||||
@@ -421,7 +512,11 @@ func TestResolveIPAddresses_ReturnsIPs(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ips := liveResolveIPs(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
ips, err := r.ResolveIPAddresses(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, ips)
|
||||
|
||||
for _, ip := range ips {
|
||||
parsed := net.ParseIP(ip)
|
||||
@@ -435,7 +530,10 @@ func TestResolveIPAddresses_Deduplicated(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ips := liveResolveIPs(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
ips, err := r.ResolveIPAddresses(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
|
||||
seen := make(map[string]bool)
|
||||
|
||||
@@ -449,7 +547,10 @@ func TestResolveIPAddresses_Sorted(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ips := liveResolveIPs(t, r, "google.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
ips, err := r.ResolveIPAddresses(ctx, "google.com")
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.True(t, sort.StringsAreSorted(ips))
|
||||
}
|
||||
@@ -460,10 +561,13 @@ func TestResolveIPAddresses_NXDomainReturnsEmpty(
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ips := liveResolveIPsAllowingEmpty(
|
||||
t, r, "this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
ctx := testContext(t)
|
||||
|
||||
ips, err := r.ResolveIPAddresses(
|
||||
ctx,
|
||||
"this-surely-does-not-exist-xyz.google.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
assert.Empty(t, ips)
|
||||
}
|
||||
|
||||
@@ -471,9 +575,11 @@ func TestResolveIPAddresses_CloudflareDomain(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
r := newTestResolver(t)
|
||||
ips := liveResolveIPs(t, r, "cloudflare.com")
|
||||
ctx := testContext(t)
|
||||
|
||||
assert.NotEmpty(t, ips)
|
||||
ips, err := r.ResolveIPAddresses(ctx, "cloudflare.com")
|
||||
require.NoError(t, err)
|
||||
require.NotEmpty(t, ips)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
@@ -517,9 +623,58 @@ func TestQueryAllNameservers_ContextCanceled(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
// Transport-failure classification (StatusTimeout / StatusError)
|
||||
// is covered in transport_test.go, against real nameservers bound on
|
||||
// loopback.
|
||||
// ----------------------------------------------------------------
|
||||
// Timeout tests
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
func TestQueryNameserverIP_Timeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
log := slog.New(slog.NewTextHandler(
|
||||
os.Stderr,
|
||||
&slog.HandlerOptions{Level: slog.LevelDebug},
|
||||
))
|
||||
|
||||
r := resolver.NewFromLoggerWithClient(
|
||||
log, &timeoutClient{},
|
||||
)
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), 10*time.Second,
|
||||
)
|
||||
t.Cleanup(cancel)
|
||||
|
||||
// Query any IP — the client always returns a timeout error.
|
||||
resp, err := r.QueryNameserverIP(
|
||||
ctx, "unreachable.test.", "192.0.2.1",
|
||||
"example.com",
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, resolver.StatusTimeout, resp.Status)
|
||||
assert.NotEmpty(t, resp.Error)
|
||||
}
|
||||
|
||||
// timeoutClient simulates DNS timeout errors for testing.
|
||||
type timeoutClient struct{}
|
||||
|
||||
func (c *timeoutClient) ExchangeContext(
|
||||
_ context.Context,
|
||||
_ *dns.Msg,
|
||||
_ string,
|
||||
) (*dns.Msg, time.Duration, error) {
|
||||
return nil, 0, &net.OpError{
|
||||
Op: "read",
|
||||
Net: "udp",
|
||||
Err: &timeoutError{},
|
||||
}
|
||||
}
|
||||
|
||||
type timeoutError struct{}
|
||||
|
||||
func (e *timeoutError) Error() string { return "i/o timeout" }
|
||||
func (e *timeoutError) Timeout() bool { return true }
|
||||
func (e *timeoutError) Temporary() bool { return true }
|
||||
|
||||
func TestResolveIPAddresses_ContextCanceled(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
package resolver_test
|
||||
|
||||
// Transport-failure classification tests.
|
||||
//
|
||||
// These are live tests, not mocks. Nothing here substitutes the
|
||||
// resolver's DNSClient: the resolver dials a real UDP socket, writes
|
||||
// a real DNS query with the real miekg/dns client, and applies its
|
||||
// real deadline and its real classification logic to what comes
|
||||
// back. The only thing under test control is which address the query
|
||||
// is sent to, and what — if anything — is listening there.
|
||||
//
|
||||
// That distinction is what the no-DNS-mocks rule in TESTING.md is
|
||||
// about. A fake DNSClient lets the code under test skip DNS entirely
|
||||
// and hands it a manufactured verdict; a nameserver bound on
|
||||
// loopback makes it speak DNS for real and earn one. Pointing a live
|
||||
// query at a nameserver of the test's choosing is no more a mock
|
||||
// than pointing it at a.root-servers.net.
|
||||
//
|
||||
// The public network cannot produce these outcomes on demand. A
|
||||
// black-holed address is not black-holed everywhere — build
|
||||
// environments that intercept UDP/53 answer it locally — so a test
|
||||
// built on one asserts on the network it happens to run on rather
|
||||
// than on the resolver. A loopback nameserver is deterministic
|
||||
// everywhere, and it is fast, because the test picks the deadline.
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"sneak.berlin/go/dnswatcher/internal/resolver"
|
||||
)
|
||||
|
||||
const (
|
||||
// transportBudget is the wall time the timeout test must stay
|
||||
// under. The resolver asks a nameserver for eight record types
|
||||
// in turn and retries each one once, so a nameserver silent on
|
||||
// every type would cost sixteen query timeouts. The test's
|
||||
// nameserver is silent on exactly one type, which costs two,
|
||||
// and this budget fails loudly if that ever stops being true.
|
||||
transportBudget = 8 * time.Second
|
||||
|
||||
// transportDeadline is the caller deadline the tests run
|
||||
// under. It is generous on purpose: these tests are about the
|
||||
// resolver classifying a nameserver's behaviour, so the
|
||||
// caller's deadline must never be the thing that expires.
|
||||
transportDeadline = 30 * time.Second
|
||||
|
||||
// silentNS and failingNS are the nameserver names reported
|
||||
// back in NameserverResponse.Nameserver. They are .test names
|
||||
// (RFC 6761) and are never resolved: the tests address the
|
||||
// nameserver by its socket address.
|
||||
silentNS = "silent.ns.test."
|
||||
failingNS = "servfail.ns.test."
|
||||
|
||||
// transportHostname is the name queried. Nothing resolves it;
|
||||
// the point is entirely how the nameserver behaves.
|
||||
transportHostname = "example.com"
|
||||
)
|
||||
|
||||
// startNameserver binds a real UDP nameserver on loopback and serves
|
||||
// every datagram it receives with handle, which returns the reply to
|
||||
// send or nil to stay silent. It returns the "host:port" address to
|
||||
// aim a query at, and stops the server when the test ends.
|
||||
func startNameserver(
|
||||
t *testing.T,
|
||||
handle func(query *dns.Msg) *dns.Msg,
|
||||
) string {
|
||||
t.Helper()
|
||||
|
||||
conn, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
require.NoError(t, err, "binding loopback nameserver")
|
||||
|
||||
stopped := make(chan struct{})
|
||||
|
||||
t.Cleanup(func() {
|
||||
_ = conn.Close()
|
||||
<-stopped
|
||||
})
|
||||
|
||||
go serveNameserver(conn, handle, stopped)
|
||||
|
||||
return conn.LocalAddr().String()
|
||||
}
|
||||
|
||||
// serveNameserver reads queries until conn is closed, replying with
|
||||
// whatever handle produces.
|
||||
func serveNameserver(
|
||||
conn net.PacketConn,
|
||||
handle func(query *dns.Msg) *dns.Msg,
|
||||
stopped chan<- struct{},
|
||||
) {
|
||||
defer close(stopped)
|
||||
|
||||
buf := make([]byte, dns.MaxMsgSize)
|
||||
|
||||
for {
|
||||
n, from, err := conn.ReadFrom(buf)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
query := new(dns.Msg)
|
||||
if query.Unpack(buf[:n]) != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
reply := handle(query)
|
||||
if reply == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
wire, err := reply.Pack()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := conn.WriteTo(wire, from); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unservedAddr returns a loopback address with nothing listening on
|
||||
// it, by binding a port and releasing it again.
|
||||
func unservedAddr(t *testing.T) string {
|
||||
t.Helper()
|
||||
|
||||
conn, err := net.ListenPacket("udp", "127.0.0.1:0")
|
||||
require.NoError(t, err, "binding loopback port")
|
||||
|
||||
addr := conn.LocalAddr().String()
|
||||
require.NoError(t, conn.Close(), "releasing loopback port")
|
||||
|
||||
return addr
|
||||
}
|
||||
|
||||
// TestQueryNameserverIP_Timeout covers the StatusTimeout branch: a
|
||||
// nameserver that takes the query and never answers.
|
||||
func TestQueryNameserverIP_Timeout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// A real nameserver that drops A queries and answers every
|
||||
// other type. Silence on one type is all the resolver needs to
|
||||
// classify the response as a timeout, and it keeps the test
|
||||
// two query timeouts long instead of sixteen.
|
||||
addr := startNameserver(t, func(query *dns.Msg) *dns.Msg {
|
||||
if len(query.Question) > 0 &&
|
||||
query.Question[0].Qtype == dns.TypeA {
|
||||
return nil
|
||||
}
|
||||
|
||||
reply := new(dns.Msg)
|
||||
reply.SetReply(query)
|
||||
|
||||
return reply
|
||||
})
|
||||
|
||||
r := newTestResolver(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), transportDeadline,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
start := time.Now()
|
||||
|
||||
resp, err := r.QueryNameserverIP(
|
||||
ctx, silentNS, addr, transportHostname,
|
||||
)
|
||||
|
||||
elapsed := time.Since(start)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
|
||||
assert.Equal(t, resolver.StatusTimeout, resp.Status)
|
||||
assert.Equal(t, "all queries timed out", resp.Error)
|
||||
assert.Empty(t, resp.Records)
|
||||
assert.Equal(t, silentNS, resp.Nameserver)
|
||||
|
||||
assert.Less(
|
||||
t, elapsed, transportBudget,
|
||||
"one silent record type must cost one query's retries, "+
|
||||
"not every record type's",
|
||||
)
|
||||
}
|
||||
|
||||
// TestQueryNameserverIP_ServFail covers the StatusError branch: a
|
||||
// nameserver that answers, and answers SERVFAIL.
|
||||
func TestQueryNameserverIP_ServFail(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
addr := startNameserver(t, func(query *dns.Msg) *dns.Msg {
|
||||
reply := new(dns.Msg)
|
||||
reply.SetRcode(query, dns.RcodeServerFailure)
|
||||
|
||||
return reply
|
||||
})
|
||||
|
||||
r := newTestResolver(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), transportDeadline,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.QueryNameserverIP(
|
||||
ctx, failingNS, addr, transportHostname,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
|
||||
assert.Equal(t, resolver.StatusError, resp.Status)
|
||||
assert.Equal(t, "server returned SERVFAIL", resp.Error)
|
||||
assert.Empty(t, resp.Records)
|
||||
assert.Equal(t, failingNS, resp.Nameserver)
|
||||
}
|
||||
|
||||
// TestQueryNameserverIP_NoListener pins the third transport outcome:
|
||||
// a refused datagram is not a timeout. The socket fails immediately
|
||||
// with ECONNREFUSED rather than going quiet, so isTimeout is false,
|
||||
// no failure flag is set, and the response classifies as NoData.
|
||||
// Asserting it here is what stops that path being mistaken for the
|
||||
// timeout path, in either direction.
|
||||
func TestQueryNameserverIP_NoListener(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
addr := unservedAddr(t)
|
||||
|
||||
r := newTestResolver(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(
|
||||
context.Background(), transportDeadline,
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
resp, err := r.QueryNameserverIP(
|
||||
ctx, silentNS, addr, transportHostname,
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, resp)
|
||||
|
||||
assert.Equal(t, resolver.StatusNoData, resp.Status)
|
||||
assert.Empty(t, resp.Records)
|
||||
}
|
||||
+493
-647
File diff suppressed because it is too large
Load Diff
+7
-15
@@ -3,17 +3,15 @@
|
||||
# this repo. Idempotent: every install is guarded by a check so already
|
||||
# installed tools are skipped. Base tooling comes from nix, apt, brew,
|
||||
# or apk (detected in that order); assumes nothing is present.
|
||||
# goimports is installed via `go install` at a pinned commit (never
|
||||
# "latest") because script/fmt runs it on the host; script/fmt-check
|
||||
# does not (it runs gofmt only).
|
||||
# The linter is NOT installed here: golangci-lint runs via docker only
|
||||
# (script/lint), pinned by image digest, so its only prerequisite is a
|
||||
# working docker.
|
||||
# golangci-lint and goimports are installed via `go install` at the same
|
||||
# pinned commits the Dockerfile uses (never "latest").
|
||||
set -eu
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
|
||||
# Pinned version, 2026-08-07 (same pin as the Dockerfile)
|
||||
# Pinned versions, 2026-08-07 (same pins as the Dockerfile)
|
||||
# golangci-lint v2.12.2
|
||||
GOLANGCI_LINT_REF="github.com/golangci/golangci-lint/v2/cmd/golangci-lint@c0d3ddc9cf3faa61a4e378e879ece580256d76e5"
|
||||
# goimports v0.42.0
|
||||
GOIMPORTS_REF="golang.org/x/tools/cmd/goimports@009367f5c17a8d4c45a961a3a509277190a9a6f0"
|
||||
|
||||
@@ -71,17 +69,11 @@ main() {
|
||||
if missing make; then pkg_install gnumake make make make; fi
|
||||
if missing go; then pkg_install go golang go go; fi
|
||||
|
||||
# Format tools, pinned via go install (installs into
|
||||
# Lint/format tools, pinned via go install (installs into
|
||||
# "$(go env GOPATH)/bin"; ensure that is on your PATH).
|
||||
if missing golangci-lint; then go install "$GOLANGCI_LINT_REF"; fi
|
||||
if missing goimports; then go install "$GOIMPORTS_REF"; fi
|
||||
|
||||
# Linting runs via docker only (script/lint). Warn, don't fail:
|
||||
# everything except `make lint` works without it.
|
||||
if missing docker; then
|
||||
echo "bootstrap: WARNING: docker not found; install it to" \
|
||||
"run make lint and make docker." >&2
|
||||
fi
|
||||
|
||||
go mod download
|
||||
|
||||
echo "bootstrap complete"
|
||||
|
||||
+8
-4
@@ -1,14 +1,18 @@
|
||||
#!/bin/sh
|
||||
# script/cibuild: run the CI build. The Dockerfile's lint stage runs
|
||||
# make fmt-check and golangci-lint; its builder stage runs make test
|
||||
# and make build. A successful build implies all of those passed.
|
||||
# script/cibuild: run the CI build. The Dockerfile runs make check, and
|
||||
# the CHECK_EPOCH build argument below is fresh on every invocation, so
|
||||
# the check layer is never served from the Docker layer cache: a
|
||||
# successful build means the checks were executed and passed on this
|
||||
# run, not on some earlier one. Only the check step and the steps after
|
||||
# it are invalidated; the toolchain install and go mod download stay
|
||||
# cached.
|
||||
set -eu
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
|
||||
main() {
|
||||
cd "$ROOT"
|
||||
docker build .
|
||||
docker build --build-arg CHECK_EPOCH="$(date +%s%N)" .
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
+2
-18
@@ -1,28 +1,12 @@
|
||||
#!/bin/sh
|
||||
# script/lint: run the linter. golangci-lint is never installed or run
|
||||
# on the host: it runs via docker only, one way, everywhere. This
|
||||
# builds Dockerfile.lint, which COPYs the repo into the digest-pinned
|
||||
# golangci-lint image and lints as a build step, so a successful build
|
||||
# means a clean lint.
|
||||
#
|
||||
# --no-cache-filter=lint forces the lint stage (source copy + linter
|
||||
# run) to execute on every invocation. Without it an unchanged tree
|
||||
# returns success in well under a second having linted nothing. The
|
||||
# deps stage (base image + go mod download) stays cached, and no global
|
||||
# cache invalidation is performed. --progress=plain keeps the linter's
|
||||
# own output visible.
|
||||
# script/lint: run the linter.
|
||||
set -eu
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
|
||||
main() {
|
||||
cd "$ROOT"
|
||||
docker build \
|
||||
--progress=plain \
|
||||
--no-cache-filter=lint \
|
||||
--target lint \
|
||||
-f Dockerfile.lint \
|
||||
.
|
||||
golangci-lint run --config .golangci.yml ./...
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
+1
-35
@@ -1,46 +1,12 @@
|
||||
#!/bin/sh
|
||||
# script/test: run the test suite.
|
||||
#
|
||||
# -count=1 disables Go's test cache, and is load-bearing here. This
|
||||
# suite queries live DNS on every run by policy (TESTING.md); a cached
|
||||
# result is a replay of an earlier run's output with no query made at
|
||||
# all. On an unchanged tree the whole suite would return success in
|
||||
# under a second having resolved nothing, which makes the repeated-run
|
||||
# green that is used as evidence for flakiness fixes worthless. Do not
|
||||
# remove it.
|
||||
#
|
||||
# Conditional verbose rerun per REPO_POLICIES.md: run quiet first so
|
||||
# CI and docker build logs stay readable, and rerun with -v only on
|
||||
# failure. The rerun also carries -count=1 (a cached replay of the
|
||||
# failure would show nothing new), and the exit status is forced to 1
|
||||
# no matter how the rerun ends: the first failure already proved the
|
||||
# suite broken, so a flaky test that passes the second time must not
|
||||
# turn the build green.
|
||||
#
|
||||
# -timeout 90s is a deliberate backstop above the 60s hard cap on
|
||||
# suite duration. Do not lower it.
|
||||
#
|
||||
# -p 1 runs one test package at a time, and is load-bearing. Live DNS
|
||||
# is a resource outside the process: the concurrency gates that keep
|
||||
# this suite from bursting at the root servers
|
||||
# (internal/resolver/livedns_test.go, internal/watcher/watcher_test.go)
|
||||
# are package-scoped, so each one only bounds its own test binary. Go
|
||||
# runs package binaries in parallel by default, so with both live-DNS
|
||||
# packages in flight at once their gates sum instead of holding, the
|
||||
# root and TLD servers rate-limit the excess, and the resolver
|
||||
# package's per-attempt deadlines expire. Serialising packages is what
|
||||
# makes each gate authoritative while its package runs.
|
||||
set -eu
|
||||
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
|
||||
main() {
|
||||
cd "$ROOT"
|
||||
go test -count=1 -p 1 -race -timeout 90s -cover ./... || {
|
||||
echo "--- Rerunning with -v for details ---" >&2
|
||||
go test -count=1 -p 1 -race -timeout 90s -v ./... || true
|
||||
exit 1
|
||||
}
|
||||
go test -v -race -timeout 30s -cover ./...
|
||||
}
|
||||
|
||||
main "$@"
|
||||
|
||||
Reference in New Issue
Block a user