...
Source file
src/net/main_conf_test.go
Documentation: net
1
2
3
4
5
6
7 package net
8
9 import "testing"
10
11
12
13 func forceGoDNS() func() {
14 c := systemConf()
15 oldGo := c.netGo
16 oldCgo := c.netCgo
17 fixup := func() {
18 c.netGo = oldGo
19 c.netCgo = oldCgo
20 }
21 c.netGo = true
22 c.netCgo = false
23 return fixup
24 }
25
26
27
28
29 func forceCgoDNS() func() {
30 c := systemConf()
31 oldGo := c.netGo
32 oldCgo := c.netCgo
33 fixup := func() {
34 c.netGo = oldGo
35 c.netCgo = oldCgo
36 }
37 c.netGo = false
38 c.netCgo = true
39 return fixup
40 }
41
42 func TestForceCgoDNS(t *testing.T) {
43 if !cgoAvailable {
44 t.Skip("cgo resolver not available")
45 }
46 defer forceCgoDNS()()
47 order, _ := systemConf().hostLookupOrder(nil, "go.dev")
48 if order != hostLookupCgo {
49 t.Fatalf("hostLookupOrder returned: %v, want cgo", order)
50 }
51 }
52
53 func TestForceGoDNS(t *testing.T) {
54 defer forceGoDNS()()
55 order, _ := systemConf().hostLookupOrder(nil, "go.dev")
56 if order == hostLookupCgo {
57 t.Fatalf("hostLookupOrder returned: %v, want go resolver order", order)
58 }
59 }
60
View as plain text