Fix short flags, AllowTCP wiring, invalid root server error, add config tests
CI / test (pull_request) Failing after 2m14s

- Register -v/-q short flag aliases sharing the same bool variable as
  --verbose/--quiet so both forms work identically
- Register -d and -dd flags; use ParseDebugLevel() helper so -d sets
  Debug=1 and -dd sets Debug=2; remove the broken strings.Count approach
- Add AllowTCP field to dns.QueryConfig; guard TCP truncation fallback in
  QueryWithExchange and IterativeQueryWithExchange behind cfg.AllowTCP;
  wire cfg.AllowTCP from CLI config into QueryConfig in main.go
- ParseRootServer() now returns ErrInvalidRootServer instead of (nil,nil)
  when the string is non-empty but net.ParseIP fails
- Add internal/config/config_test.go covering ParseQueryType, ParseUDPSize,
  Validate, GetDomain, ParseRootServer, ParseDebugLevel, and the
  --always-tcp/--allow-tcp cross-check
- Add TestQueryNoTCPFallbackWhenDisabled to dns/query_test.go
- Update existing truncation tests to set AllowTCP:true
- Add TODO comments on display flags not yet wired to output layer

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
Gary Hansen
2026-06-08 01:29:46 +10:00
co-authored by Copilot multica-agent
parent d66dcbe067
commit 93c5ca7bba
5 changed files with 332 additions and 45 deletions
+50 -8
View File
@@ -110,10 +110,11 @@ func TestQueryTCPFallbackOnTruncation(t *testing.T) {
}
cfg := &QueryConfig{
UDPSize: 2048,
Timeout: 5,
Retries: 1,
UseTCP: false,
UDPSize: 2048,
Timeout: 5,
Retries: 1,
UseTCP: false,
AllowTCP: true,
}
server := net.ParseIP("8.8.8.8")
@@ -272,10 +273,11 @@ func TestQueryTCPFallbackFailsThenRetries(t *testing.T) {
}
cfg := &QueryConfig{
UDPSize: 2048,
Timeout: 5,
Retries: 2,
UseTCP: false,
UDPSize: 2048,
Timeout: 5,
Retries: 2,
UseTCP: false,
AllowTCP: true,
}
server := net.ParseIP("8.8.8.8")
@@ -287,3 +289,43 @@ func TestQueryTCPFallbackFailsThenRetries(t *testing.T) {
t.Errorf("expected 4 calls (2 retries x UDP+TCP), got %d", callCount)
}
}
func TestQueryNoTCPFallbackWhenDisabled(t *testing.T) {
truncatedResp := new(dns.Msg)
truncatedResp.Truncated = true
truncatedResp.SetReply(new(dns.Msg))
var mu sync.Mutex
calls := []bool{}
exchangeFn := func(ctx context.Context, server string, msg *dns.Msg, useTCP bool) (*dns.Msg, error) {
mu.Lock()
defer mu.Unlock()
calls = append(calls, useTCP)
return truncatedResp.Copy(), nil
}
cfg := &QueryConfig{
UDPSize: 2048,
Timeout: 5,
Retries: 1,
UseTCP: false,
AllowTCP: false, // TCP fallback must be suppressed
}
server := net.ParseIP("8.8.8.8")
resp, err := QueryWithExchange(context.Background(), server, "example.com", TypeA, cfg, exchangeFn)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
// Only one UDP call; no TCP fallback.
if len(calls) != 1 {
t.Fatalf("expected 1 exchange call (no TCP fallback), got %d", len(calls))
}
if calls[0] != false {
t.Error("expected UDP-only call")
}
if !resp.Truncated {
t.Error("expected truncated response to be returned as-is")
}
}