mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	
		
			
	
	
		
			34 lines
		
	
	
		
			606 B
		
	
	
	
		
			Go
		
	
	
	
	
	
		
		
			
		
	
	
			34 lines
		
	
	
		
			606 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 
								 | 
							
								package test
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								import (
							 | 
						||
| 
								 | 
							
									"testing"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									"github.com/miekg/dns"
							 | 
						||
| 
								 | 
							
								)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								func TestEDNS0(t *testing.T) {
							 | 
						||
| 
								 | 
							
									corefile := `.:0 {
							 | 
						||
| 
								 | 
							
										whoami
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								`
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									i, udp, _, err := CoreDNSServerAndPorts(corefile)
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										t.Fatalf("Could not get CoreDNS serving instance: %s", err)
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									defer i.Stop()
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									m := new(dns.Msg)
							 | 
						||
| 
								 | 
							
									m.SetQuestion("example.org.", dns.TypeSOA)
							 | 
						||
| 
								 | 
							
									m.SetEdns0(4096, true)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									resp, err := dns.Exchange(m, udp)
							 | 
						||
| 
								 | 
							
									if err != nil {
							 | 
						||
| 
								 | 
							
										t.Fatalf("Expected to receive reply, but didn't: %v", err)
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
									opt := resp.Extra[len(resp.Extra)-1]
							 | 
						||
| 
								 | 
							
									if opt.Header().Rrtype != dns.TypeOPT {
							 | 
						||
| 
								 | 
							
										t.Errorf("Last RR must be OPT record")
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |