mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	Remove the word middleware (#1067)
* Rename middleware to plugin first pass; mostly used 'sed', few spots where I manually changed text. This still builds a coredns binary. * fmt error * Rename AddMiddleware to AddPlugin * Readd AddMiddleware to remain backwards compat
This commit is contained in:
		
							
								
								
									
										71
									
								
								plugin/reverse/reverse_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								plugin/reverse/reverse_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| package reverse | ||||
|  | ||||
| import ( | ||||
| 	"net" | ||||
| 	"regexp" | ||||
| 	"testing" | ||||
|  | ||||
| 	"github.com/coredns/coredns/plugin" | ||||
| 	"github.com/coredns/coredns/plugin/pkg/dnsrecorder" | ||||
| 	"github.com/coredns/coredns/plugin/test" | ||||
|  | ||||
| 	"github.com/miekg/dns" | ||||
| 	"golang.org/x/net/context" | ||||
| ) | ||||
|  | ||||
| func TestReverse(t *testing.T) { | ||||
| 	_, net4, _ := net.ParseCIDR("10.1.1.0/24") | ||||
| 	regexIP4, _ := regexp.Compile("^.*ip-" + regexMatchV4 + "\\.example\\.org\\.$") | ||||
|  | ||||
| 	em := Reverse{ | ||||
| 		Networks: networks{network{ | ||||
| 			IPnet:        net4, | ||||
| 			Zone:         "example.org", | ||||
| 			Template:     "ip-{ip}.example.org.", | ||||
| 			RegexMatchIP: regexIP4, | ||||
| 		}}, | ||||
| 		Fallthrough: false, | ||||
| 	} | ||||
|  | ||||
| 	tests := []struct { | ||||
| 		next          plugin.Handler | ||||
| 		qname         string | ||||
| 		qtype         uint16 | ||||
| 		expectedCode  int | ||||
| 		expectedReply string | ||||
| 		expectedErr   error | ||||
| 	}{ | ||||
| 		{ | ||||
| 			next:          test.NextHandler(dns.RcodeSuccess, nil), | ||||
| 			qname:         "test.ip-10.1.1.2.example.org", | ||||
| 			expectedCode:  dns.RcodeSuccess, | ||||
| 			expectedReply: "10.1.1.2", | ||||
| 			expectedErr:   nil, | ||||
| 		}, | ||||
| 	} | ||||
|  | ||||
| 	ctx := context.TODO() | ||||
|  | ||||
| 	for i, tr := range tests { | ||||
| 		req := new(dns.Msg) | ||||
|  | ||||
| 		tr.qtype = dns.TypeA | ||||
| 		req.SetQuestion(dns.Fqdn(tr.qname), tr.qtype) | ||||
|  | ||||
| 		rec := dnsrecorder.New(&test.ResponseWriter{}) | ||||
| 		code, err := em.ServeDNS(ctx, rec, req) | ||||
|  | ||||
| 		if err != tr.expectedErr { | ||||
| 			t.Errorf("Test %d: Expected error %v, but got %v", i, tr.expectedErr, err) | ||||
| 		} | ||||
| 		if code != int(tr.expectedCode) { | ||||
| 			t.Errorf("Test %d: Expected status code %d, but got %d", i, tr.expectedCode, code) | ||||
| 		} | ||||
| 		if tr.expectedReply != "" { | ||||
| 			answer := rec.Msg.Answer[0].(*dns.A).A.String() | ||||
| 			if answer != tr.expectedReply { | ||||
| 				t.Errorf("Test %d: Expected answer %s, but got %s", i, tr.expectedReply, answer) | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user