mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
Return all records for SRV queries
Return all SRV records and assume the client is smart enough to make the call. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
@@ -43,7 +43,7 @@ func TestTraffic(t *testing.T) {
|
||||
cla: &xdspb.ClusterLoadAssignment{},
|
||||
cluster: "does-not-exist", qtype: dns.TypeA, rcode: dns.RcodeNameError, ns: true,
|
||||
},
|
||||
// healthy backend
|
||||
// healthy endpoint
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
@@ -58,7 +58,7 @@ func TestTraffic(t *testing.T) {
|
||||
},
|
||||
cluster: "web", qtype: dns.TypeAAAA, rcode: dns.RcodeSuccess, answer: "::1",
|
||||
},
|
||||
// unknown backend
|
||||
// unknown endpoint
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
@@ -66,7 +66,7 @@ func TestTraffic(t *testing.T) {
|
||||
},
|
||||
cluster: "web", qtype: dns.TypeA, rcode: dns.RcodeSuccess, ns: true,
|
||||
},
|
||||
// unknown backend and healthy backend
|
||||
// unknown endpoint and healthy endpoint
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
@@ -77,7 +77,7 @@ func TestTraffic(t *testing.T) {
|
||||
},
|
||||
cluster: "web", qtype: dns.TypeA, rcode: dns.RcodeSuccess, answer: "127.0.0.2",
|
||||
},
|
||||
// SRV query healthy backend
|
||||
// SRV query healthy endpoint
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
@@ -97,6 +97,17 @@ func TestTraffic(t *testing.T) {
|
||||
},
|
||||
cluster: "endpoint-0.web", qtype: dns.TypeA, rcode: dns.RcodeSuccess, answer: "127.0.0.2",
|
||||
},
|
||||
// A query for endpoint-1.
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
Endpoints: endpoints([]EndpointHealth{
|
||||
{"127.0.0.2", 18008, corepb.HealthStatus_HEALTHY},
|
||||
{"127.0.0.3", 18008, corepb.HealthStatus_HEALTHY},
|
||||
}),
|
||||
},
|
||||
cluster: "endpoint-1.web", qtype: dns.TypeA, rcode: dns.RcodeSuccess, answer: "127.0.0.3",
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
@@ -142,6 +153,58 @@ func TestTraffic(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrafficSRV(t *testing.T) {
|
||||
c, err := xds.New("127.0.0.1:0", "test-id", grpc.WithInsecure())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tr := &Traffic{c: c, origins: []string{"lb.example.org."}}
|
||||
|
||||
tests := []struct {
|
||||
cla *xdspb.ClusterLoadAssignment
|
||||
cluster string
|
||||
qtype uint16
|
||||
rcode int
|
||||
answer int // number of records in answer section
|
||||
}{
|
||||
// SRV query healthy endpoint
|
||||
{
|
||||
cla: &xdspb.ClusterLoadAssignment{
|
||||
ClusterName: "web",
|
||||
Endpoints: endpoints([]EndpointHealth{
|
||||
{"127.0.0.2", 18008, corepb.HealthStatus_HEALTHY},
|
||||
{"127.0.0.3", 18008, corepb.HealthStatus_HEALTHY},
|
||||
}),
|
||||
},
|
||||
cluster: "web", qtype: dns.TypeSRV, rcode: dns.RcodeSuccess, answer: 2,
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
for i, tc := range tests {
|
||||
a := xds.NewAssignment()
|
||||
a.SetClusterLoadAssignment("web", tc.cla) // web is our cluster
|
||||
c.SetAssignments(a)
|
||||
|
||||
m := new(dns.Msg)
|
||||
cl := dnsutil.Join(tc.cluster, tr.origins[0])
|
||||
m.SetQuestion(cl, tc.qtype)
|
||||
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||
_, err := tr.ServeDNS(ctx, rec, m)
|
||||
if err != nil {
|
||||
t.Errorf("Test %d: Expected no error, but got %q", i, err)
|
||||
}
|
||||
if rec.Msg.Rcode != tc.rcode {
|
||||
t.Errorf("Test %d: Expected no rcode %d, but got %d", i, tc.rcode, rec.Msg.Rcode)
|
||||
}
|
||||
if tc.answer != len(rec.Msg.Answer) {
|
||||
t.Fatalf("Test %d: Expected %d answers, but got %d", i, tc.answer, len(rec.Msg.Answer))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type EndpointHealth struct {
|
||||
Address string
|
||||
Port uint16
|
||||
|
||||
Reference in New Issue
Block a user