fix: remove duplicate test declarations from PR #12/#13 conflict
CI / test (push) Has been cancelled
CI / test (push) Has been cancelled
Phase 4.2 (PR #12) and test coverage improvement (PR #13) independently added overlapping test functions. Remove duplicates from PR #13 files: - internal/dns/iterative_test.go: remove TestExtractNSNames, TestExtractNSNamesEmpty, TestIterativeQueryWithExchangeSuccess, TestIterativeQueryWithExchangeNilResponse, TestIterativeQueryWithExchangeTCPFallback (kept in roots_test.go and query_test.go from PR #12) - internal/output/coverage_test.go: remove TestRRDataStringDefault, TestContainsString, TestCollectUniqueServerIPs, TestNewFormatterNilWriter (kept in stats_test.go and formatter_test.go from PR #12) 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
dbd9322a1b
commit
dd667f734c
@@ -10,38 +10,6 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestIterativeQueryWithExchangeSuccess(t *testing.T) {
|
||||
resp := new(dns.Msg)
|
||||
resp.SetReply(new(dns.Msg))
|
||||
resp.RecursionDesired = false
|
||||
resp.Answer = append(resp.Answer, &dns.A{
|
||||
Hdr: dns.RR_Header{Name: "example.com.", Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 300},
|
||||
A: net.ParseIP("93.184.216.34"),
|
||||
})
|
||||
|
||||
exchangeFn := func(ctx context.Context, server string, msg *dns.Msg, useTCP bool) (*dns.Msg, error) {
|
||||
if msg.RecursionDesired {
|
||||
t.Error("iterative query should have RecursionDesired=false")
|
||||
}
|
||||
return resp.Copy(), nil
|
||||
}
|
||||
|
||||
cfg := &QueryConfig{
|
||||
UDPSize: 2048,
|
||||
Retries: 1,
|
||||
UseTCP: false,
|
||||
}
|
||||
|
||||
server := net.ParseIP("8.8.8.8")
|
||||
result, err := IterativeQueryWithExchange(context.Background(), server, "example.com", TypeA, cfg, exchangeFn)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(result.Answer) != 1 {
|
||||
t.Fatalf("expected 1 answer, got %d", len(result.Answer))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterativeQueryWithExchangeNilConfig(t *testing.T) {
|
||||
resp := new(dns.Msg)
|
||||
resp.SetReply(new(dns.Msg))
|
||||
@@ -57,76 +25,6 @@ func TestIterativeQueryWithExchangeNilConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterativeQueryWithExchangeNilResponse(t *testing.T) {
|
||||
var mu sync.Mutex
|
||||
callCount := 0
|
||||
exchangeFn := func(ctx context.Context, server string, msg *dns.Msg, useTCP bool) (*dns.Msg, error) {
|
||||
mu.Lock()
|
||||
callCount++
|
||||
mu.Unlock()
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
cfg := &QueryConfig{
|
||||
UDPSize: 2048,
|
||||
Retries: 2,
|
||||
UseTCP: false,
|
||||
}
|
||||
|
||||
server := net.ParseIP("8.8.8.8")
|
||||
_, err := IterativeQueryWithExchange(context.Background(), server, "example.com", TypeA, cfg, exchangeFn)
|
||||
if err == nil {
|
||||
t.Fatal("expected error when response is nil")
|
||||
}
|
||||
if callCount != 2 {
|
||||
t.Errorf("expected 2 attempts, got %d", callCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterativeQueryWithExchangeTCPFallback(t *testing.T) {
|
||||
truncated := new(dns.Msg)
|
||||
truncated.Truncated = true
|
||||
truncated.SetReply(new(dns.Msg))
|
||||
|
||||
full := new(dns.Msg)
|
||||
full.SetReply(new(dns.Msg))
|
||||
full.Answer = append(full.Answer, &dns.A{
|
||||
Hdr: dns.RR_Header{Name: "example.com.", Rrtype: dns.TypeA},
|
||||
A: net.ParseIP("1.2.3.4"),
|
||||
})
|
||||
|
||||
var mu sync.Mutex
|
||||
calls := []bool{}
|
||||
exchangeFn := func(ctx context.Context, server string, msg *dns.Msg, useTCP bool) (*dns.Msg, error) {
|
||||
mu.Lock()
|
||||
calls = append(calls, useTCP)
|
||||
mu.Unlock()
|
||||
if !useTCP {
|
||||
return truncated.Copy(), nil
|
||||
}
|
||||
return full.Copy(), nil
|
||||
}
|
||||
|
||||
cfg := &QueryConfig{
|
||||
UDPSize: 2048,
|
||||
Retries: 1,
|
||||
UseTCP: false,
|
||||
AllowTCP: true,
|
||||
}
|
||||
|
||||
server := net.ParseIP("8.8.8.8")
|
||||
result, err := IterativeQueryWithExchange(context.Background(), server, "example.com", TypeA, cfg, exchangeFn)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if len(calls) != 2 {
|
||||
t.Errorf("expected 2 calls (UDP + TCP), got %d", len(calls))
|
||||
}
|
||||
if len(result.Answer) != 1 {
|
||||
t.Fatalf("expected 1 answer, got %d", len(result.Answer))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterativeQueryWithExchangeAlwaysTCP(t *testing.T) {
|
||||
resp := new(dns.Msg)
|
||||
resp.SetReply(new(dns.Msg))
|
||||
@@ -203,24 +101,6 @@ func TestIterativeQueryWithExchangeContextCancel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractNSNames(t *testing.T) {
|
||||
rrs := []dns.RR{
|
||||
&dns.NS{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeNS}, Ns: "a.root-servers.net."},
|
||||
&dns.NS{Hdr: dns.RR_Header{Name: ".", Rrtype: dns.TypeNS}, Ns: "b.root-servers.net."},
|
||||
}
|
||||
names := extractNSNames(rrs)
|
||||
if len(names) != 2 {
|
||||
t.Fatalf("expected 2 names, got %d", len(names))
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractNSNamesEmpty(t *testing.T) {
|
||||
names := extractNSNames(nil)
|
||||
if len(names) != 0 {
|
||||
t.Errorf("expected 0 names, got %d", len(names))
|
||||
}
|
||||
}
|
||||
|
||||
func TestIterativeQueryWithExchangeZeroUDPSize(t *testing.T) {
|
||||
resp := new(dns.Msg)
|
||||
resp.SetReply(new(dns.Msg))
|
||||
|
||||
Reference in New Issue
Block a user