| 
									
										
										
										
											2021-01-13 09:16:01 +01:00
										 |  |  | package transfer
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							|  |  |  | 	"context"
 | 
					
						
							|  |  |  | 	"fmt"
 | 
					
						
							|  |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/coredns/coredns/plugin/test"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type badwriter struct {
 | 
					
						
							|  |  |  | 	dns.ResponseWriter
 | 
					
						
							|  |  |  | 	count int
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (w *badwriter) WriteMsg(res *dns.Msg) error { return fmt.Errorf("failed to write msg") }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestWriteMessageFailed(t *testing.T) {
 | 
					
						
							|  |  |  | 	transfer := newTestTransfer()
 | 
					
						
							|  |  |  | 	ctx := context.TODO()
 | 
					
						
							| 
									
										
										
										
											2021-02-05 10:51:29 +01:00
										 |  |  | 	w := &badwriter{ResponseWriter: &test.ResponseWriter{TCP: true}}
 | 
					
						
							| 
									
										
										
										
											2021-01-13 09:16:01 +01:00
										 |  |  | 	m := &dns.Msg{}
 | 
					
						
							|  |  |  | 	m.SetAxfr("example.org.")
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, err := transfer.ServeDNS(ctx, w, m)
 | 
					
						
							|  |  |  | 	if err == nil {
 | 
					
						
							|  |  |  | 		t.Error("Expected error, got none")
 | 
					
						
							|  |  |  | 	}
 | 
					
						
							|  |  |  | }
 |