mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	Move all (almost all) Go files in middleware into their own packages. This makes for better naming and discoverability. Lot of changes elsewhere to make this change. The middleware.State was renamed to request.Request which is better, but still does not cover all use-cases. It was also moved out middleware because it is used by `dnsserver` as well. A pkg/dnsutil packages was added for shared, handy, dns util functions. All normalize functions are now put in normalize.go
		
			
				
	
	
		
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			65 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package test
 | |
| 
 | |
| import (
 | |
| 	"io/ioutil"
 | |
| 	"log"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/miekg/coredns/middleware/proxy"
 | |
| 	"github.com/miekg/coredns/middleware/test"
 | |
| 	"github.com/miekg/coredns/request"
 | |
| 
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| const exampleOrg = `; example.org test file
 | |
| example.org.		IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600
 | |
| example.org.		IN	NS	b.iana-servers.net.
 | |
| example.org.		IN	NS	a.iana-servers.net.
 | |
| example.org.		IN	A	127.0.0.1
 | |
| example.org.		IN	A	127.0.0.2
 | |
| `
 | |
| 
 | |
| func TestLookupProxy(t *testing.T) {
 | |
| 	name, rm, err := test.TempFile(t, ".", exampleOrg)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("failed to created zone: %s", err)
 | |
| 	}
 | |
| 	defer rm()
 | |
| 
 | |
| 	corefile := `example.org:0 {
 | |
|        file ` + name + `
 | |
| }
 | |
| `
 | |
| 
 | |
| 	i, err := CoreDNSServer(corefile)
 | |
| 	if err != nil {
 | |
| 		t.Fatalf("could not get CoreDNS serving instance: %s", err)
 | |
| 	}
 | |
| 
 | |
| 	udp, _ := CoreDNSServerPorts(i, 0)
 | |
| 	if udp == "" {
 | |
| 		t.Fatalf("could not get udp listening port")
 | |
| 	}
 | |
| 	defer i.Stop()
 | |
| 
 | |
| 	log.SetOutput(ioutil.Discard)
 | |
| 
 | |
| 	p := proxy.New([]string{udp})
 | |
| 	state := request.Request{W: &test.ResponseWriter{}, Req: new(dns.Msg)}
 | |
| 	resp, err := p.Lookup(state, "example.org.", dns.TypeA)
 | |
| 	if err != nil {
 | |
| 		t.Fatal("Expected to receive reply, but didn't")
 | |
| 	}
 | |
| 	// expect answer section with A record in it
 | |
| 	if len(resp.Answer) == 0 {
 | |
| 		t.Error("Expected to at least one RR in the answer section, got none")
 | |
| 	}
 | |
| 	if resp.Answer[0].Header().Rrtype != dns.TypeA {
 | |
| 		t.Errorf("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
 | |
| 	}
 | |
| 	if resp.Answer[0].(*dns.A).A.String() != "127.0.0.1" {
 | |
| 		t.Errorf("Expected 127.0.0.1, got: %d", resp.Answer[0].(*dns.A).A.String())
 | |
| 	}
 | |
| }
 |