| 
									
										
										
										
											2022-03-18 14:11:14 +00:00
										 |  |  | //go:build etcd | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | package etcd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/etcd/msg" | 
					
						
							| 
									
										
										
										
											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" | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestGroupLookup(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2017-09-16 14:13:28 +01:00
										 |  |  | 	etc := newEtcdPlugin() | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 	for _, serv := range servicesGroup { | 
					
						
							|  |  |  | 		set(t, etc, serv.Key, 0, serv) | 
					
						
							|  |  |  | 		defer delete(t, etc, serv.Key) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	for _, tc := range dnsTestCasesGroup { | 
					
						
							| 
									
										
										
										
											2016-03-28 21:18:16 +01:00
										 |  |  | 		m := tc.Msg() | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		rec := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2016-06-11 08:00:47 +10:00
										 |  |  | 		_, err := etc.ServeDNS(ctxt, rec, m) | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 			t.Errorf("Expected no error, got %v", err) | 
					
						
							| 
									
										
										
										
											2016-04-12 21:30:08 +01:00
										 |  |  | 			continue | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 11:10:16 +01:00
										 |  |  | 		resp := rec.Msg | 
					
						
							| 
									
										
										
										
											2019-01-19 11:23:13 +00:00
										 |  |  | 		if err := test.SortAndCheck(resp, tc); err != nil { | 
					
						
							|  |  |  | 			t.Error(err) | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Note the key is encoded as DNS name, while in "reality" it is a etcd path. | 
					
						
							|  |  |  | var servicesGroup = []*msg.Service{ | 
					
						
							|  |  |  | 	{Host: "127.0.0.1", Key: "a.dom.skydns.test.", Group: "g1"}, | 
					
						
							|  |  |  | 	{Host: "127.0.0.2", Key: "b.sub.dom.skydns.test.", Group: "g1"}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{Host: "127.0.0.1", Key: "a.dom2.skydns.test.", Group: "g1"}, | 
					
						
							|  |  |  | 	{Host: "127.0.0.2", Key: "b.sub.dom2.skydns.test.", Group: ""}, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	{Host: "127.0.0.1", Key: "a.dom1.skydns.test.", Group: "g1"}, | 
					
						
							|  |  |  | 	{Host: "127.0.0.2", Key: "b.sub.dom1.skydns.test.", Group: "g2"}, | 
					
						
							| 
									
										
										
										
											2022-04-04 14:59:16 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{Text: "foo", Key: "a.dom3.skydns.test.", Group: "g1"}, | 
					
						
							|  |  |  | 	{Text: "bar", Key: "b.sub.dom3.skydns.test.", Group: "g1"}, | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | var dnsTestCasesGroup = []test.Case{ | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 	// Groups | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2022-04-04 14:59:16 -04:00
										 |  |  | 		// hits the group 'g1' and only includes those A records | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		Qname: "dom.skydns.test.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 			test.A("dom.skydns.test. 300 IN A 127.0.0.1"), | 
					
						
							|  |  |  | 			test.A("dom.skydns.test. 300 IN A 127.0.0.2"), | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// One has group, the other has not...  Include the non-group always. | 
					
						
							|  |  |  | 		Qname: "dom2.skydns.test.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 			test.A("dom2.skydns.test. 300 IN A 127.0.0.1"), | 
					
						
							|  |  |  | 			test.A("dom2.skydns.test. 300 IN A 127.0.0.2"), | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		// The groups differ. | 
					
						
							|  |  |  | 		Qname: "dom1.skydns.test.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2016-04-11 07:56:38 +01:00
										 |  |  | 			test.A("dom1.skydns.test. 300 IN A 127.0.0.1"), | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2022-04-04 14:59:16 -04:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		// hits the group 'g1' and only includes those TXT records | 
					
						
							|  |  |  | 		Qname: "dom3.skydns.test.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT("dom3.skydns.test. 300 IN TXT bar"), | 
					
						
							|  |  |  | 			test.TXT("dom3.skydns.test. 300 IN TXT foo"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-03-25 10:32:12 +00:00
										 |  |  | } |