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
+23 -6
View File
@@ -11,12 +11,13 @@ import (
)
var (
ErrInvalidQueryType = errors.New("invalid query type")
ErrInvalidUDPSize = errors.New("UDP size must be between 512 and 4096")
ErrInvalidMaxDepth = errors.New("max depth must be between 1 and 100")
ErrInvalidRetries = errors.New("retries must be between 0 and 10")
ErrMissingDomain = errors.New("domain is required")
ErrInvalidQueryType = errors.New("invalid query type")
ErrInvalidUDPSize = errors.New("UDP size must be between 512 and 4096")
ErrInvalidMaxDepth = errors.New("max depth must be between 1 and 100")
ErrInvalidRetries = errors.New("retries must be between 0 and 10")
ErrMissingDomain = errors.New("domain is required")
ErrAlwaysTCPRequiresTCP = errors.New("--always-tcp requires --allow-tcp")
ErrInvalidRootServer = errors.New("invalid root server IP address")
)
type Config struct {
@@ -138,7 +139,23 @@ func (c *Config) ParseRootServer() (net.IP, error) {
if c.RootServer == "" {
return nil, nil
}
return net.ParseIP(c.RootServer), nil
ip := net.ParseIP(c.RootServer)
if ip == nil {
return nil, fmt.Errorf("%w: %s", ErrInvalidRootServer, c.RootServer)
}
return ip, nil
}
// ParseDebugLevel returns the debug verbosity level from the -d and -dd flag values.
// dd=true → 2 (library debug), d=true → 1 (application debug), neither → 0.
func ParseDebugLevel(d, dd bool) int {
if dd {
return 2
}
if d {
return 1
}
return 0
}
func PrintUsage() {