MCPcopy
hub / github.com/AdguardTeam/dnsproxy / TestCollectQueryStats

Function TestCollectQueryStats

proxy/stats_test.go:19–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestCollectQueryStats(t *testing.T) {
20 var (
21 testReq = &dns.Msg{
22 Question: []dns.Question{{
23 Name: "test.",
24 Qtype: dns.TypeA,
25 Qclass: dns.ClassINET,
26 }},
27 }
28
29 defaultTrustedProxies netutil.SubnetSet = netutil.SliceSubnetSet{
30 netip.MustParsePrefix("0.0.0.0/0"),
31 netip.MustParsePrefix("::0/0"),
32 }
33 )
34
35 ups := &dnsproxytest.Upstream{
36 OnExchange: func(req *dns.Msg) (resp *dns.Msg, err error) {
37 return (&dns.Msg{}).SetReply(req), nil
38 },
39 OnAddress: func() (addr string) { return "upstream" },
40 OnClose: func() (err error) { return nil },
41 }
42
43 failUps := &dnsproxytest.Upstream{
44 OnExchange: func(req *dns.Msg) (resp *dns.Msg, err error) {
45 return nil, errors.Error("exchange error")
46 },
47 OnAddress: func() (addr string) { return "fail.upstream" },
48 OnClose: func() (err error) { return nil },
49 }
50
51 conf := &proxy.Config{
52 Logger: testLogger,
53 UDPListenAddr: []*net.UDPAddr{net.UDPAddrFromAddrPort(localhostAnyPort)},
54 TCPListenAddr: []*net.TCPAddr{net.TCPAddrFromAddrPort(localhostAnyPort)},
55 TrustedProxies: defaultTrustedProxies,
56 }
57
58 testCases := []struct {
59 wantErr assert.ErrorAssertionFunc
60 wantMainErr assert.BoolAssertionFunc
61 wantFallbackErr assert.BoolAssertionFunc
62 config *proxy.UpstreamConfig
63 fallbackConfig *proxy.UpstreamConfig
64 name string
65 mode proxy.UpstreamMode
66 wantMainCount int
67 wantFallbackCount int
68 }{{
69 wantErr: assert.NoError,
70 wantMainErr: assert.False,
71 wantFallbackErr: assert.False,
72 config: &proxy.UpstreamConfig{
73 Upstreams: []upstream.Upstream{ups},
74 },
75 fallbackConfig: &proxy.UpstreamConfig{
76 Upstreams: []upstream.Upstream{ups},

Callers

nothing calls this directly

Calls 5

QueryStatisticsMethod · 0.95
NewFunction · 0.92
assertQueryStatsFunction · 0.85
ResolveMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…