MCPcopy Index your code
hub / github.com/AdguardTeam/dnsproxy / TestProxy_Resolve_cache

Function TestProxy_Resolve_cache

proxy/proxy_test.go:65–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

63}
64
65func TestProxy_Resolve_cache(t *testing.T) {
66 const host = "example.test."
67
68 ups := &dnsproxytest.Upstream{
69 OnAddress: func() (addr string) { return "stub" },
70 OnClose: func() (err error) { return nil },
71 }
72 ups.OnExchange = func(req *dns.Msg) (resp *dns.Msg, err error) {
73 resp = (&dns.Msg{}).SetReply(req)
74 resp.Answer = append(resp.Answer, &dns.A{
75 Hdr: dns.RR_Header{
76 Name: req.Question[0].Name,
77 Rrtype: dns.TypeA,
78 Class: dns.ClassINET,
79 Ttl: 60,
80 },
81 A: net.IP{192, 0, 2, 0},
82 })
83
84 return resp, nil
85 }
86
87 upsConf := &proxy.UpstreamConfig{
88 Upstreams: []upstream.Upstream{ups},
89 }
90
91 testCases := []struct {
92 customUpstreamConf *proxy.CustomUpstreamConfig
93 wantCachedWithConf assert.BoolAssertionFunc
94 wantCachedGlobal assert.BoolAssertionFunc
95 name string
96 prxCacheEnabled bool
97 }{{
98 customUpstreamConf: nil,
99 wantCachedWithConf: assert.True,
100 wantCachedGlobal: assert.True,
101 name: "global_cache",
102 prxCacheEnabled: true,
103 }, {
104 customUpstreamConf: newCustomUpstreamConfig(ups, true),
105 wantCachedWithConf: assert.True,
106 wantCachedGlobal: assert.False,
107 name: "custom_cache",
108 prxCacheEnabled: false,
109 }, {
110 customUpstreamConf: newCustomUpstreamConfig(ups, false),
111 wantCachedWithConf: assert.False,
112 wantCachedGlobal: assert.False,
113 name: "custom_cache_only_upstreams",
114 prxCacheEnabled: false,
115 }, {
116 customUpstreamConf: newCustomUpstreamConfig(ups, true),
117 wantCachedWithConf: assert.True,
118 wantCachedGlobal: assert.False,
119 name: "two_caches_enabled",
120 prxCacheEnabled: true,
121 }, {
122 customUpstreamConf: nil,

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
newCustomUpstreamConfigFunction · 0.85
isCachedWithCustomConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…