| 1 |
package ecs_test |
| 2 |
|
| 3 |
import ( |
| 4 |
"context" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"codeberg.org/miekg/dns" |
| 8 |
"codeberg.org/miekg/dns/cmd/atomdns/handlers/ecs" |
| 9 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsctx" |
| 10 |
"codeberg.org/miekg/dns/dnstest" |
| 11 |
"codeberg.org/miekg/dns/dnsutil" |
| 12 |
) |
| 13 |
|
| 14 |
func TestEcs(t *testing.T) { |
| 15 |
e := &ecs.Ecs{} |
| 16 |
|
| 17 |
ecs := &dns.SUBNET{Family: dnsutil.IPv4Family, Netmask: 32, Address: dnstest.IPv4} |
| 18 |
m := dnstest.NewMsg() |
| 19 |
m.Pseudo = []dns.RR{ecs} |
| 20 |
m.Pack() |
| 21 |
|
| 22 |
tw := dnstest.NewTestRecorder() |
| 23 |
next := dns.HandlerFunc(func(ctx context.Context, _ dns.ResponseWriter, _ *dns.Msg) { |
| 24 |
address := dnsctx.Value(ctx, e.Key()+"/addr") |
| 25 |
if address == nil { |
| 26 |
t.Fatal("expected ecs/addr, got none") |
| 27 |
} |
| 28 |
if address != dnstest.IPv4 { |
| 29 |
t.Fatalf("expected %s, got %s", dnstest.IPv4, address) |
| 30 |
} |
| 31 |
}) |
| 32 |
ctx := context.TODO() |
| 33 |
e.HandlerFunc(next).ServeDNS(ctx, tw, m) |
| 34 |
} |