mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	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:
		| @@ -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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user