mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
test(plugin): add tests for any (#7341)
This commit is contained in:
@@ -26,3 +26,42 @@ func TestAny(t *testing.T) {
|
||||
t.Errorf("Expected HINFO, but got %q", rec.Msg.Answer[0].(*dns.HINFO).Cpu)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnyNonANYQuery(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
qtype uint16
|
||||
}{
|
||||
{"A query", dns.TypeA},
|
||||
{"AAAA query", dns.TypeAAAA},
|
||||
{"MX query", dns.TypeMX},
|
||||
{"TXT query", dns.TypeTXT},
|
||||
{"CNAME query", dns.TypeCNAME},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion("example.org.", tt.qtype)
|
||||
|
||||
nextCalled := false
|
||||
a := &Any{
|
||||
Next: test.HandlerFunc(func(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
nextCalled = true
|
||||
return 0, nil
|
||||
}),
|
||||
}
|
||||
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
_, err := a.ServeDNS(context.TODO(), rec, req)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Expected no error, but got %q", err)
|
||||
}
|
||||
|
||||
if !nextCalled {
|
||||
t.Error("Expected Next handler to be called for non-ANY query")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user