-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathnet_http_doh_test.go
More file actions
78 lines (63 loc) · 1.63 KB
/
net_http_doh_test.go
File metadata and controls
78 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package connect
import (
"context"
"fmt"
"net/netip"
"slices"
"time"
"testing"
"github.com/go-playground/assert/v2"
)
func TestDohQuery(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
settings := DefaultDohSettings()
testIp1, err := netip.ParseAddr("1.1.1.1")
assert.Equal(t, err, nil)
testIp2, err := netip.ParseAddr("10.10.10.10")
assert.Equal(t, err, nil)
for range 10 {
ips := DohQuery(ctx, 4, "A", settings, "test1.bringyour.com")
if len(ips) == 0 {
// timeout, try again
fmt.Printf("[doh]timeout. Will wait 1s and try again ...\n")
select {
case <-time.After(1 * time.Second):
continue
}
}
assert.Equal(t, len(ips), 2)
ttl1 := ips[testIp1]
assert.NotEqual(t, ttl1, 0)
ttl2 := ips[testIp2]
assert.NotEqual(t, ttl2, 0)
}
}
func TestDohCache(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
settings := DefaultDohSettings()
dohCache := NewDohCache(settings)
testIp1, err := netip.ParseAddr("1.1.1.1")
assert.Equal(t, err, nil)
testIp2, err := netip.ParseAddr("10.10.10.10")
assert.Equal(t, err, nil)
for range 10 {
ips := dohCache.Query(ctx, "A", "test1.bringyour.com")
if len(ips) == 0 {
// timeout, try again
fmt.Printf("[doh]timeout. Will wait 1s and try again ...\n")
select {
case <-time.After(1 * time.Second):
continue
}
}
assert.Equal(t, len(ips), 2)
assert.Equal(t, slices.Contains(ips, testIp1), true)
assert.Equal(t, slices.Contains(ips, testIp2), true)
}
for range 10 {
ips := dohCache.Query(ctx, "A", "test-local.bringyour.com")
assert.Equal(t, len(ips), 0)
}
}