mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
@@ -161,12 +161,9 @@ func TestTrafficLocality(t *testing.T) {
|
|||||||
tr := &Traffic{c: c, origins: []string{"lb.example.org."}}
|
tr := &Traffic{c: c, origins: []string{"lb.example.org."}}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
cla *xdspb.ClusterLoadAssignment
|
cla *xdspb.ClusterLoadAssignment
|
||||||
cluster string
|
loc xds.Locality // where we run
|
||||||
loc xds.Locality // where we run
|
answer string
|
||||||
qtype uint16
|
|
||||||
rcode int
|
|
||||||
answer int // number of records in answer section
|
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
cla: &xdspb.ClusterLoadAssignment{
|
cla: &xdspb.ClusterLoadAssignment{
|
||||||
@@ -177,13 +174,12 @@ func TestTrafficLocality(t *testing.T) {
|
|||||||
{"127.0.0.2", 18008, corepb.HealthStatus_HEALTHY}},
|
{"127.0.0.2", 18008, corepb.HealthStatus_HEALTHY}},
|
||||||
xds.Locality{Region: "us"}),
|
xds.Locality{Region: "us"}),
|
||||||
endpointsWithLocality([]EndpointHealth{
|
endpointsWithLocality([]EndpointHealth{
|
||||||
{"127.0.1.1", 18008, corepb.HealthStatus_HEALTHY},
|
{"127.0.1.1", 18008, corepb.HealthStatus_HEALTHY}},
|
||||||
{"127.0.1.2", 18008, corepb.HealthStatus_HEALTHY}},
|
|
||||||
xds.Locality{Region: "eu"})...,
|
xds.Locality{Region: "eu"})...,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
cluster: "web", qtype: dns.TypeA, rcode: dns.RcodeSuccess, answer: 2,
|
answer: "127.0.1.1",
|
||||||
loc: xds.Locality{Region: "eu"}, // our location
|
loc: xds.Locality{Region: "eu"}, // our location
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,23 +187,18 @@ func TestTrafficLocality(t *testing.T) {
|
|||||||
|
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
a := xds.NewAssignment()
|
a := xds.NewAssignment()
|
||||||
a.SetClusterLoadAssignment("web", tc.cla) // web is our cluster
|
a.SetClusterLoadAssignment("web", tc.cla)
|
||||||
c.SetAssignments(a)
|
c.SetAssignments(a)
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg).SetQuestion(dnsutil.Join("web", tr.origins[0]), dns.TypeA)
|
||||||
cl := dnsutil.Join(tc.cluster, tr.origins[0])
|
|
||||||
m.SetQuestion(cl, tc.qtype)
|
|
||||||
|
|
||||||
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||||
_, err := tr.ServeDNS(ctx, rec, m)
|
_, err := tr.ServeDNS(ctx, rec, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Test %d: Expected no error, but got %q", i, err)
|
t.Errorf("Test %d: Expected no error, but got %q", i, err)
|
||||||
}
|
}
|
||||||
if rec.Msg.Rcode != tc.rcode {
|
if x := rec.Msg.Answer[0].(*dns.A).A.String(); x != tc.answer {
|
||||||
t.Errorf("Test %d: Expected no rcode %d, but got %d", i, tc.rcode, rec.Msg.Rcode)
|
t.Fatalf("Test %d: Expected %s, but got %s", i, tc.answer, x)
|
||||||
}
|
|
||||||
if tc.answer != len(rec.Msg.Answer) {
|
|
||||||
t.Fatalf("Test %d: Expected %d answers, but got %d", i, tc.answer, len(rec.Msg.Answer))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user