Add support for fallthrough to the grpc plugin (#7359)

Fixes: https://github.com/coredns/coredns/issues/7358

Signed-off-by: Blake Barnett <bbarnett@groq.com>
This commit is contained in:
blakebarnett
2025-06-06 04:58:17 -07:00
committed by GitHub
parent 0eb5542035
commit 6cba588951
5 changed files with 118 additions and 1 deletions

View File

@@ -3,10 +3,12 @@ package grpc
import (
"context"
"errors"
"strings"
"testing"
"github.com/coredns/coredns/pb"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/fall"
"github.com/coredns/coredns/plugin/test"
"github.com/miekg/dns"
@@ -73,3 +75,30 @@ func TestGRPC(t *testing.T) {
})
}
}
// Test that fallthrough works correctly when there's no next plugin
func TestGRPCFallthroughNoNext(t *testing.T) {
g := newGRPC() // Use the constructor to properly initialize
g.Fall = fall.Root // Enable fallthrough for all zones
g.Next = nil // No next plugin
g.from = "."
// Create a test request
r := new(dns.Msg)
r.SetQuestion("test.example.org.", dns.TypeA)
w := &test.ResponseWriter{}
// Should return SERVFAIL since no backends are configured and no next plugin
rcode, err := g.ServeDNS(context.Background(), w, r)
// Should not return the "no next plugin found" error
if err != nil && strings.Contains(err.Error(), "no next plugin found") {
t.Errorf("Expected no 'no next plugin found' error, got: %v", err)
}
// Should return SERVFAIL
if rcode != dns.RcodeServerFailure {
t.Errorf("Expected SERVFAIL when no backends and no next plugin, got: %d", rcode)
}
}