mirror of https://github.com/golang/go.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: 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:
parent
202ba7deab
commit
f2fcea5009
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
package net
|
package net
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
// forceGoDNS forces the resolver configuration to use the pure Go resolver
|
// forceGoDNS forces the resolver configuration to use the pure Go resolver
|
||||||
// and returns a fixup function to restore the old settings.
|
// and returns a fixup function to restore the old settings.
|
||||||
func forceGoDNS() func() {
|
func forceGoDNS() func() {
|
||||||
|
|
@ -36,3 +38,22 @@ func forceCgoDNS() func() {
|
||||||
c.netCgo = true
|
c.netCgo = true
|
||||||
return fixup
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue