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: 34a84fad33
GitHub-Pull-Request: golang/go#59922
Reviewed-on: https://go-review.googlesource.com/c/go/+/491255
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2023-05-02 18:40:56 +00:00 committed by Gopher Robot
parent 202ba7deab
commit f2fcea5009
1 changed files with 21 additions and 0 deletions

View File

@ -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)
}
}