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