mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	* mw/kubernetes: remove federation and cidr Remove both as we have a corefile syntax change that handles cidr and remove federation because that is going to be its own middleware. * backwards incompat changes This PR: * removes cidr from kubernetes (core Corefile feature now) * removes federation from kubernets (comes back as new middleware) * [remove autopath - which was already gone, so that already was backwards incompat] * adds `fallthrough` to the *etcd* middleware and makes you enable it. * Fail on unknown properties * documentation * Disable TestHealthCheck as it uses realtime and fails
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package kubernetes
 | |
| 
 | |
| import (
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/coredns/coredns/request"
 | |
| 	"github.com/miekg/dns"
 | |
| )
 | |
| 
 | |
| func TestParseRequest(t *testing.T) {
 | |
| 	k := Kubernetes{Zones: []string{zone}}
 | |
| 
 | |
| 	tests := []struct {
 | |
| 		query    string
 | |
| 		qtype    uint16
 | |
| 		expected string // output from r.String()
 | |
| 	}{
 | |
| 		{
 | |
| 			// valid SRV request
 | |
| 			"_http._tcp.webs.mynamespace.svc.inter.webs.test.", dns.TypeSRV,
 | |
| 			"http.tcp..webs.mynamespace.svc.intern.webs.tests.",
 | |
| 		},
 | |
| 		{
 | |
| 			// wildcard acceptance
 | |
| 			"*.any.*.any.svc.inter.webs.test.", dns.TypeSRV,
 | |
| 			"*.any..*.any.svc.intern.webs.tests.",
 | |
| 		},
 | |
| 		{
 | |
| 			// A request of endpoint
 | |
| 			"1-2-3-4.webs.mynamespace.svc.inter.webs.test.", dns.TypeA,
 | |
| 			"..1-2-3-4.webs.mynamespace.svc.intern.webs.tests.",
 | |
| 		},
 | |
| 		{
 | |
| 			"inter.webs.test.", dns.TypeNS,
 | |
| 			"......intern.webs.tests.",
 | |
| 		},
 | |
| 	}
 | |
| 	for i, tc := range tests {
 | |
| 		m := new(dns.Msg)
 | |
| 		m.SetQuestion(tc.query, tc.qtype)
 | |
| 		state := request.Request{Zone: zone, Req: m}
 | |
| 
 | |
| 		r, e := k.parseRequest(state)
 | |
| 		if e != nil {
 | |
| 			t.Errorf("Test %d, expected no error, got '%v'.", i, e)
 | |
| 		}
 | |
| 		rs := r.String()
 | |
| 		if rs != tc.expected {
 | |
| 			t.Errorf("Test %d, expected (stringyfied) recordRequest: %s, got %s", i, tc.expected, rs)
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestParseInvalidRequest(t *testing.T) {
 | |
| 	k := Kubernetes{Zones: []string{zone}}
 | |
| 
 | |
| 	invalid := map[string]uint16{
 | |
| 		"_http._tcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeA,   // A requests cannot have port or protocol
 | |
| 		"_http._pcp.webs.mynamespace.svc.inter.webs.test.": dns.TypeSRV, // SRV protocol must be tcp or udp
 | |
| 		"_http._tcp.ep.webs.ns.svc.inter.webs.test.":       dns.TypeSRV, // SRV requests cannot have an endpoint
 | |
| 		"_*._*.webs.mynamespace.svc.inter.webs.test.":      dns.TypeSRV, // SRV request with invalid wildcards
 | |
| 
 | |
| 	}
 | |
| 
 | |
| 	for query, qtype := range invalid {
 | |
| 		m := new(dns.Msg)
 | |
| 		m.SetQuestion(query, qtype)
 | |
| 		state := request.Request{Zone: zone, Req: m}
 | |
| 
 | |
| 		if _, e := k.parseRequest(state); e == nil {
 | |
| 			t.Errorf("Expected error from %s:%d, got none", query, qtype)
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| const zone = "intern.webs.tests."
 |