| 
									
										
										
										
											2016-03-22 08:30:30 +00:00
										 |  |  | package proxy
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"io/ioutil"
 | 
					
						
							|  |  |  | 	"log"
 | 
					
						
							|  |  |  | 	"os"
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/coredns/middleware"
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestLookupProxy(t *testing.T) {
 | 
					
						
							|  |  |  | 	// TODO(miek): make this fakeDNS backend and ask the question locally
 | 
					
						
							|  |  |  | 	log.SetOutput(ioutil.Discard)
 | 
					
						
							|  |  |  | 	defer log.SetOutput(os.Stderr)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p := New([]string{"8.8.8.8:53"})
 | 
					
						
							| 
									
										
										
										
											2016-03-22 10:29:48 +00:00
										 |  |  | 	resp, err := p.Lookup(fakeState(), "example.org.", dns.TypeA)
 | 
					
						
							| 
									
										
										
										
											2016-03-22 08:30:30 +00:00
										 |  |  | 	if err != nil {
 | 
					
						
							|  |  |  | 		t.Error("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.Error("Expected RR to A, got: %d", resp.Answer[0].Header().Rrtype)
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func fakeState() middleware.State {
 | 
					
						
							|  |  |  | 	return middleware.State{W: &middleware.TestResponseWriter{}, Req: new(dns.Msg)}
 | 
					
						
							|  |  |  | }
 |