@@ -2382,19 +2382,34 @@ func testGoLookupIPCNAMEOrderHostsAliases(t *testing.T, mode hostLookupOrder, lo
23822382// This isn't a great test as it just tests the dnsmessage package
23832383// against itself.
23842384func TestDNSPacketSize (t * testing.T ) {
2385+ t .Run ("enabled" , func (t * testing.T ) {
2386+ testDNSPacketSize (t , false )
2387+ })
2388+ t .Run ("disabled" , func (t * testing.T ) {
2389+ testDNSPacketSize (t , true )
2390+ })
2391+ }
2392+
2393+ func testDNSPacketSize (t * testing.T , disable bool ) {
23852394 fake := fakeDNSServer {
23862395 rh : func (_ , _ string , q dnsmessage.Message , _ time.Time ) (dnsmessage.Message , error ) {
2387- if len (q .Additionals ) == 0 {
2388- t .Error ("missing EDNS record" )
2389- } else if opt , ok := q .Additionals [0 ].Body .(* dnsmessage.OPTResource ); ! ok {
2390- t .Errorf ("additional record type %T, expected OPTResource" , q .Additionals [0 ])
2391- } else if len (opt .Options ) != 0 {
2392- t .Errorf ("found %d Options, expected none" , len (opt .Options ))
2396+ if disable {
2397+ if len (q .Additionals ) > 0 {
2398+ t .Error ("unexpected additional record" )
2399+ }
23932400 } else {
2394- got := int (q .Additionals [0 ].Header .Class )
2395- t .Logf ("EDNS packet size == %d" , got )
2396- if got != maxDNSPacketSize {
2397- t .Errorf ("EDNS packet size == %d, want %d" , got , maxDNSPacketSize )
2401+ if len (q .Additionals ) == 0 {
2402+ t .Error ("missing EDNS record" )
2403+ } else if opt , ok := q .Additionals [0 ].Body .(* dnsmessage.OPTResource ); ! ok {
2404+ t .Errorf ("additional record type %T, expected OPTResource" , q .Additionals [0 ])
2405+ } else if len (opt .Options ) != 0 {
2406+ t .Errorf ("found %d Options, expected none" , len (opt .Options ))
2407+ } else {
2408+ got := int (q .Additionals [0 ].Header .Class )
2409+ t .Logf ("EDNS packet size == %d" , got )
2410+ if got != maxDNSPacketSize {
2411+ t .Errorf ("EDNS packet size == %d, want %d" , got , maxDNSPacketSize )
2412+ }
23982413 }
23992414 }
24002415
@@ -2427,6 +2442,10 @@ func TestDNSPacketSize(t *testing.T) {
24272442 },
24282443 }
24292444
2445+ if disable {
2446+ t .Setenv ("GODEBUG" , "netedns0=0" )
2447+ }
2448+
24302449 r := & Resolver {PreferGo : true , Dial : fake .DialContext }
24312450 if _ , err := r .LookupIPAddr (context .Background (), "go.dev" ); err != nil {
24322451 t .Errorf ("lookup failed: %v" , err )
0 commit comments