mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-04 03:03:14 -05:00 
			
		
		
		
	* Update build * Update Go to 1.23.0 * Update minimum Go version to 1.22. * Update golangci-lint to v1.60.1. * Make GitHub action version hash/tag consistent. * Increase dependabot open PRs from 5 to 20. Signed-off-by: SuperQ <superq@gmail.com> * Fixup lint issue. Signed-off-by: SuperQ <superq@gmail.com> --------- Signed-off-by: SuperQ <superq@gmail.com>
		
			
				
	
	
		
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			59 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package transfer
 | 
						|
 | 
						|
import (
 | 
						|
	"context"
 | 
						|
	"errors"
 | 
						|
	"testing"
 | 
						|
 | 
						|
	"github.com/coredns/coredns/plugin/pkg/dnstest"
 | 
						|
	"github.com/coredns/coredns/plugin/test"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
)
 | 
						|
 | 
						|
type (
 | 
						|
	t1 struct{}
 | 
						|
	t2 struct{}
 | 
						|
)
 | 
						|
 | 
						|
func (t t1) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
 | 
						|
	const z = "example.org."
 | 
						|
	if zone != z {
 | 
						|
		return nil, ErrNotAuthoritative
 | 
						|
	}
 | 
						|
	return nil, errors.New(z)
 | 
						|
}
 | 
						|
func (t t2) Transfer(zone string, serial uint32) (<-chan []dns.RR, error) {
 | 
						|
	const z = "sub.example.org."
 | 
						|
	if zone != z {
 | 
						|
		return nil, ErrNotAuthoritative
 | 
						|
	}
 | 
						|
	return nil, errors.New(z)
 | 
						|
}
 | 
						|
 | 
						|
func TestZoneSelection(t *testing.T) {
 | 
						|
	tr := &Transfer{
 | 
						|
		Transferers: []Transferer{t1{}, t2{}},
 | 
						|
		xfrs: []*xfr{
 | 
						|
			{
 | 
						|
				Zones: []string{"example.org."},
 | 
						|
				to:    []string{"192.0.2.1"}, // RFC 5737 IP, no interface should have this address.
 | 
						|
			},
 | 
						|
			{
 | 
						|
				Zones: []string{"sub.example.org."},
 | 
						|
				to:    []string{"*"},
 | 
						|
			},
 | 
						|
		},
 | 
						|
	}
 | 
						|
	r := new(dns.Msg)
 | 
						|
	r.SetAxfr("sub.example.org.")
 | 
						|
	w := dnstest.NewRecorder(&test.ResponseWriter{TCP: true})
 | 
						|
	_, err := tr.ServeDNS(context.TODO(), w, r)
 | 
						|
	if err == nil {
 | 
						|
		t.Fatal("Expected error, got nil")
 | 
						|
	}
 | 
						|
	if x := err.Error(); x != "sub.example.org." {
 | 
						|
		t.Errorf("Expected transfer for zone %s, got %s", "sub.example.org", x)
 | 
						|
	}
 | 
						|
}
 |