5
5
"sort"
6
6
"sync"
7
7
"testing"
8
+ "time"
8
9
9
10
"github.com/miekg/dns"
10
11
"github.com/stretchr/testify/assert"
@@ -195,6 +196,7 @@ var findXByFqdnTestCases = []struct {
195
196
primaryNs string
196
197
nameservers []string
197
198
expectedError string // regular expression
199
+ timeout time.Duration
198
200
}{
199
201
{
200
202
desc : "domain is a CNAME" ,
@@ -237,6 +239,7 @@ var findXByFqdnTestCases = []struct {
237
239
zone : "google.com." ,
238
240
primaryNs : "ns1.google.com." ,
239
241
nameservers : []string {":7053" , ":8053" , "8.8.8.8:53" },
242
+ timeout : 500 * time .Millisecond ,
240
243
},
241
244
{
242
245
desc : "only non-existent nameservers" ,
@@ -246,7 +249,8 @@ var findXByFqdnTestCases = []struct {
246
249
// NOTE: On Windows, net.DialContext finds a way down to the ContectEx syscall.
247
250
// There a fault is marked as "connectex", not "connect", see
248
251
// https://cs.opensource.google/go/go/+/refs/tags/go1.19.5:src/net/fd_windows.go;l=112
249
- expectedError : `^could not find the start of authority for mail\.google\.com.: dial tcp :9053: connect(ex)?:` ,
252
+ expectedError : `^could not find the start of authority for mail\.google\.com.: dial tcp :9053:.+` ,
253
+ timeout : 500 * time .Millisecond ,
250
254
},
251
255
{
252
256
desc : "no nameservers" ,
@@ -277,6 +281,11 @@ func TestFindZoneByFqdnCustom(t *testing.T) {
277
281
func TestFindPrimaryNsByFqdnCustom (t * testing.T ) {
278
282
for _ , test := range findXByFqdnTestCases {
279
283
t .Run (test .desc , func (t * testing.T ) {
284
+ origTimeout := dnsTimeout
285
+ if test .timeout > 0 {
286
+ dnsTimeout = test .timeout
287
+ }
288
+
280
289
ClearFqdnCache ()
281
290
282
291
ns , err := FindPrimaryNsByFqdnCustom (test .fqdn , test .nameservers )
@@ -287,6 +296,8 @@ func TestFindPrimaryNsByFqdnCustom(t *testing.T) {
287
296
require .NoError (t , err )
288
297
assert .Equal (t , test .primaryNs , ns )
289
298
}
299
+
300
+ dnsTimeout = origTimeout
290
301
})
291
302
}
292
303
}
0 commit comments