mirror of
https://github.com/coredns/coredns.git
synced 2025-11-02 18:23:25 -05:00
Add middleware.NextOrFailure (#462)
This checks if the next middleware to be called is nil, and if so returns ServerFailure and an error. This makes the next calling more robust and saves some lines of code. Also prefix the error with the name of the middleware to aid in debugging.
This commit is contained in:
@@ -3,7 +3,6 @@ package whoami
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
"github.com/miekg/coredns/middleware/pkg/dnsrecorder"
|
||||
"github.com/miekg/coredns/middleware/test"
|
||||
|
||||
@@ -15,7 +14,6 @@ func TestWhoami(t *testing.T) {
|
||||
wh := Whoami{}
|
||||
|
||||
tests := []struct {
|
||||
next middleware.Handler
|
||||
qname string
|
||||
qtype uint16
|
||||
expectedCode int
|
||||
@@ -23,7 +21,6 @@ func TestWhoami(t *testing.T) {
|
||||
expectedErr error
|
||||
}{
|
||||
{
|
||||
next: test.NextHandler(dns.RcodeSuccess, nil),
|
||||
qname: "example.org",
|
||||
qtype: dns.TypeA,
|
||||
expectedCode: dns.RcodeSuccess,
|
||||
@@ -35,7 +32,6 @@ func TestWhoami(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
|
||||
for i, tc := range tests {
|
||||
wh.Next = tc.next
|
||||
req := new(dns.Msg)
|
||||
req.SetQuestion(dns.Fqdn(tc.qname), tc.qtype)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user