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