From c0f59f1e1d8cddd0e6f87adc3b7a56fb05805a17 Mon Sep 17 00:00:00 2001 From: boratanrikulu Date: Sat, 27 Jul 2024 19:48:35 +0300 Subject: [PATCH] avoid using dns cache in tests --- internal/ebpf/testing.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/ebpf/testing.go b/internal/ebpf/testing.go index fe8b1ff..f8f1084 100644 --- a/internal/ebpf/testing.go +++ b/internal/ebpf/testing.go @@ -1,6 +1,7 @@ package ebpf import ( + "context" "net" "testing" "time" @@ -104,9 +105,16 @@ func TTCPWrite(c *qt.C, address string, ok bool) { c.Assert(err, qt.IsNil) } -// TDNSLookup tests if the DNS lookup works well. +// TDNSLookup tests if the DNS lookup works well without using DNS cache. func TDNSLookup(c *qt.C, dns string, ok bool) { - _, err := net.LookupIP(dns) + r := &net.Resolver{ + PreferGo: true, + Dial: func(ctx context.Context, network, address string) (net.Conn, error) { + return net.Dial(network, "8.8.8.8:53") + }, + } + + _, err := r.LookupIP(context.Background(), "ip", dns) if !ok { c.Assert(err, qt.IsNotNil) return