]> Cypherpunks repositories - gostls13.git/commitdiff
net: add tests for forceGoDNS and forceCgoDNS
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Tue, 2 May 2023 18:40:56 +0000 (18:40 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 12 May 2023 19:21:10 +0000 (19:21 +0000)
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 <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>
src/net/main_conf_test.go

index e5994f5e5f156ba4459a1a5603bd9ed7abe1a5e3..28a1cb8351c24bc3d34f4c9fe84e0183e701fd1b 100644 (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)
+       }
+}