From: Mateusz Poliwczak Date: Tue, 2 May 2023 18:40:56 +0000 (+0000) Subject: net: add tests for forceGoDNS and forceCgoDNS X-Git-Tag: go1.21rc1~541 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f2fcea5009d06d14b9869879f897c4ffb11cf953;p=gostls13.git net: add tests for forceGoDNS and forceCgoDNS There was a bug in forceCgoDNS (CL 479416), it was fixed by CL 487196, so add a test case for it. Change-Id: I2010374451ef236dc2898d9e9ea006eb8b40d02e GitHub-Last-Rev: 34a84fad33404c66c3ee20cb63803214c42e991d GitHub-Pull-Request: golang/go#59922 Reviewed-on: https://go-review.googlesource.com/c/go/+/491255 Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Run-TryBot: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor --- diff --git a/src/net/main_conf_test.go b/src/net/main_conf_test.go index e5994f5e5f..28a1cb8351 100644 --- a/src/net/main_conf_test.go +++ b/src/net/main_conf_test.go @@ -6,6 +6,8 @@ package net +import "testing" + // forceGoDNS forces the resolver configuration to use the pure Go resolver // and returns a fixup function to restore the old settings. func forceGoDNS() func() { @@ -36,3 +38,22 @@ func forceCgoDNS() func() { c.netCgo = true return fixup } + +func TestForceCgoDNS(t *testing.T) { + if !cgoAvailable { + t.Skip("cgo resolver not available") + } + defer forceCgoDNS()() + order, _ := systemConf().hostLookupOrder(nil, "go.dev") + if order != hostLookupCgo { + t.Fatalf("hostLookupOrder returned: %v, want cgo", order) + } +} + +func TestForceGoDNS(t *testing.T) { + defer forceGoDNS()() + order, _ := systemConf().hostLookupOrder(nil, "go.dev") + if order == hostLookupCgo { + t.Fatalf("hostLookupOrder returned: %v, want go resolver order", order) + } +}