| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | package kubernetes
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import (
 | 
					
						
							| 
									
										
										
										
											2018-04-22 08:34:35 +01:00
										 |  |  | 	"context"
 | 
					
						
							| 
									
										
										
										
											2019-09-05 09:07:55 -04:00
										 |  |  | 	"net"
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 	"testing"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/pkg/dnstest"
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/test"
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns"
 | 
					
						
							|  |  |  | )
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | var kubeApexCases = []test.Case{
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeSOA,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Answer: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.SOA("cluster.local.	5	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							|  |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeHINFO,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Ns: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.SOA("cluster.local.	5	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							|  |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeNS,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Answer: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.NS("cluster.local. 5     IN      NS     ns.dns.cluster.local."),
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 		Extra: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.A("ns.dns.cluster.local.   5       IN      A       127.0.0.1"),
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							| 
									
										
										
										
											2018-04-18 12:12:28 -04:00
										 |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeA,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Ns: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.SOA("cluster.local.	5	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
 | 
					
						
							| 
									
										
										
										
											2018-04-18 12:12:28 -04:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							|  |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeAAAA,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Ns: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.SOA("cluster.local.	5	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
 | 
					
						
							| 
									
										
										
										
											2018-04-18 12:12:28 -04:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							|  |  |  | 	{
 | 
					
						
							|  |  |  | 		Qname: "cluster.local.", Qtype: dns.TypeSRV,
 | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess,
 | 
					
						
							|  |  |  | 		Ns: []dns.RR{
 | 
					
						
							| 
									
										
										
										
											2019-01-19 05:25:52 -05:00
										 |  |  | 			test.SOA("cluster.local.	5	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 5"),
 | 
					
						
							| 
									
										
										
										
											2018-04-18 12:12:28 -04:00
										 |  |  | 		},
 | 
					
						
							|  |  |  | 	},
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestServeDNSApex(t *testing.T) {
 | 
					
						
							|  |  |  | 	k := New([]string{"cluster.local."})
 | 
					
						
							|  |  |  | 	k.APIConn = &APIConnServeTest{}
 | 
					
						
							|  |  |  | 	k.Next = test.NextHandler(dns.RcodeSuccess, nil)
 | 
					
						
							| 
									
										
										
										
											2019-09-05 09:07:55 -04:00
										 |  |  | 	k.localIPs = []net.IP{net.ParseIP("127.0.0.1")}
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 	ctx := context.TODO()
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for i, tc := range kubeApexCases {
 | 
					
						
							|  |  |  | 		r := tc.Msg()
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		w := dnstest.NewRecorder(&test.ResponseWriter{})
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_, err := k.ServeDNS(ctx, w, r)
 | 
					
						
							|  |  |  | 		if err != tc.Error {
 | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Test %d, expected no error, got %v", i, err)
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 			return
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 		if tc.Error != nil {
 | 
					
						
							|  |  |  | 			continue
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		resp := w.Msg
 | 
					
						
							|  |  |  | 		if resp == nil {
 | 
					
						
							|  |  |  | 			t.Fatalf("Test %d, got nil message and no error ford", i)
 | 
					
						
							|  |  |  | 		}
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil {
 | 
					
						
							| 
									
										
										
										
											2019-09-05 09:07:55 -04:00
										 |  |  | 			t.Errorf("Test %d: %v", i, err)
 | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		}
 | 
					
						
							| 
									
										
										
										
											2017-08-23 14:07:10 +01:00
										 |  |  | 	}
 | 
					
						
							|  |  |  | }
 |