Enable protogetter in golangci config and update all protobuf field
access to use getter methods instead of direct field access.
Getter methods provide safer nil pointer handling and return
appropriate default values, following protobuf best practices.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable intrange linter to enforce modern Go range syntax over
traditional for loops, by converting:
for i := 0; i < n; i++
to:
for i := range n
Adding type conversions where needed for compatibility
with existing uint64 parameters.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable canonicalheader linter to enforce proper HTTP header casing.
This ensures headers use Go's canonical format (e.g., "Content-Type"
instead of "content-type") for consistency.
Fixes header casing in DoH implementation.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Ensure Dial exits early or returns error when Transport has been
stopped, instead of blocking on the dial or ret channels. This removes
a potential goroutine leak where callers could pile up waiting
forever under heavy load.
Add select guards before send and receive, and propagate clear error
values so callers can handle shutdown gracefully.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add test suite covering thread-safe random number generator with
tests for:
- Constructor with various seed values (positive, zero, negative)
- Deterministic behavior verification with same seeds
- Permutation generation and validation
- Concurrent access safety with multiple goroutines
- Mixed operations under concurrent load
Also clarify package documentation to explicitly state this is
for load balancing and server selection, not cryptographic use.
The math/rand usage is intentional for performance in non-security
contexts like upstream server selection and DNS record shuffling.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add comprehensive unit test coverage for DNS-over-gRPC and
DNS-over-QUIC server implementations:
- server_grpc_test.go: Tests gRPC server creation, TLS config,
lifecycle methods, Query handling, and response writer
- server_quic_test.go: Tests QUIC server creation, custom limits,
message validation, DOQ message parsing, and writer interface
Tests focus on component-level validation with mocks,
complementing existing integration tests without overlap.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable copyloopvar linter and remove redundant variable
shadowing in Kubernetes plugin metadata handling. This pattern is
no longer needed in Go 1.22+ where loop variables are automatically
captured correctly in closures.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Enable the usetesting linter in golangci.yml configuration to
enforce proper testing practices. Replace manual temporary
directory and file creation with t.TempDir() in test files.
This improves test reliability by ensuring proper cleanup and
follows Go testing best practices.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add conditional test skipping for bind and readme tests that rely on
Linux-specific loopback interface behavior. These tests reference
network configurations that may not exist on for e.g. macOS or other
platforms, causing spurious test failures.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add comprehensive tests for multiple components including server blocks
inspection, configuration handling, DoH/DoQ writers, and server startup
functions. Increases overall test coverage from 27% to 38.4% with
particular focus on register.go, https.go, quic.go, and config.go.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
The rewrite plugin modifies DNS messages, affecting the request
size observed in the coredns_dns_request_size_bytes metric.
This change captures the original request size before any plugins
can modify it. It adds a functional options pattern to Report() to
pass this information while maintaining API compatibility.
Tests have been added to verify the fix prevents rewrite from
affecting the request size metrics.
Docs included.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This fixes a bug introduced in
https://github.com/coredns/coredns/pull/6547 which resulted in the zone
being added to IPv4 addresses. This bug results in a failure to start
when binding to an interface with a link-local IPv4 address assigned to
it, with the following error:
$ ./coredns -conf=/etc/coredns/Corefile
maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined
lookup 169.254.1.1%dummy0: no such host
Signed-off-by: Mark Mickan <mark.mickan@openlms.net>
Co-authored-by: Mark Mickan <mark.mickan@openlms.net>
Add tests for previously untested functions:
- edns0.go: test supportedOptions function
- request.go: test address methods, protocol handling, and EDNS0
options
- writer.go: test ScrubWriter implementation
Improves overall package test coverage from 39.5% to 77.8%.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add comprehensive test coverage for the coremain package,
focusing on configuration loading, version information, and
output formatting. Test coverage improves from 0% to 59.7%.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
Add environment variable setup step for Go version in the e2e tests
job of the GitHub workflow. This ensures consistent Go version usage
across all test jobs and fixes the warning about missing go-version
input.
Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>