- Unit tests for all internal packages exceeding 80% coverage:
- internal/config: 86.2% (ParseMaxDepth, ParseRetries, validation paths)
- internal/dns: 82.9% (IterativeQueryWithExchange, mock DNS server, roots)
- internal/fingerprint: 96.4% (unchanged, already excellent)
- internal/output: 86.7% (formatters, stats, JSON/text output, hooks)
- internal/traverse: 86.7% (SetHooks, ResolveNS, processReferral,
ensureRDFalse, resolveGlueViaSystem, newAQuery, Referral.Resolve)
- Integration tests in internal/integration/:
- End-to-end traversal with mock DNS exchange function
- Referral chain traversal (root -> TLD -> authoritative)
- CNAME resolution and loop detection
- NXDOMAIN and SERVFAIL response handling
- Max depth enforcement
- Context cancellation
- TraverserHooks event delivery
- Mock DNS server helper in internal/dns/roots_test.go using miekg/dns
(enables deterministic testing without network dependency)
- CI updated with coverage reporting step
- Makefile: added 'cover' target for local HTML coverage reports
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Copilot
multica-agent
parent
fe1afe2a97
commit
5d1e5ca86c
@@ -214,3 +214,76 @@ func TestParseDebugLevel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMaxDepthValid(t *testing.T) {
|
||||
cases := []string{"1", "20", "100"}
|
||||
for _, s := range cases {
|
||||
v, err := ParseMaxDepth(s)
|
||||
if err != nil {
|
||||
t.Errorf("ParseMaxDepth(%q) unexpected error: %v", s, err)
|
||||
}
|
||||
if v < 1 || v > 100 {
|
||||
t.Errorf("ParseMaxDepth(%q) = %d, out of range", s, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseMaxDepthInvalid(t *testing.T) {
|
||||
cases := []string{"0", "101", "notanumber"}
|
||||
for _, s := range cases {
|
||||
_, err := ParseMaxDepth(s)
|
||||
if err == nil {
|
||||
t.Errorf("ParseMaxDepth(%q): expected error", s)
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidMaxDepth) {
|
||||
t.Errorf("ParseMaxDepth(%q): expected ErrInvalidMaxDepth, got %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRetriesValid(t *testing.T) {
|
||||
cases := []string{"0", "5", "10"}
|
||||
for _, s := range cases {
|
||||
v, err := ParseRetries(s)
|
||||
if err != nil {
|
||||
t.Errorf("ParseRetries(%q) unexpected error: %v", s, err)
|
||||
}
|
||||
if v < 0 || v > 10 {
|
||||
t.Errorf("ParseRetries(%q) = %d, out of range", s, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRetriesInvalid(t *testing.T) {
|
||||
cases := []string{"-1", "11", "notanumber"}
|
||||
for _, s := range cases {
|
||||
_, err := ParseRetries(s)
|
||||
if err == nil {
|
||||
t.Errorf("ParseRetries(%q): expected error", s)
|
||||
}
|
||||
if !errors.Is(err, ErrInvalidRetries) {
|
||||
t.Errorf("ParseRetries(%q): expected ErrInvalidRetries, got %v", s, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBadQueryType(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
cfg.QueryType = "BOGUS"
|
||||
if err := cfg.Validate(); !errors.Is(err, ErrInvalidQueryType) {
|
||||
t.Errorf("expected ErrInvalidQueryType, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultConfigIsValid(t *testing.T) {
|
||||
cfg := DefaultConfig()
|
||||
if cfg.QueryType != "A" {
|
||||
t.Errorf("QueryType = %q, want A", cfg.QueryType)
|
||||
}
|
||||
if cfg.MaxDepth != 20 {
|
||||
t.Errorf("MaxDepth = %d, want 20", cfg.MaxDepth)
|
||||
}
|
||||
if cfg.Retries != 2 {
|
||||
t.Errorf("Retries = %d, want 2", cfg.Retries)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user