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

Function TestCacheDO

proxy/cache_internal_test.go:184–220  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestCacheDO(t *testing.T) {
185 testCache := newTestCache(t, nil)
186
187 // Make a request.
188 request := (&dns.Msg{}).SetQuestion("google.com.", dns.TypeA)
189
190 // Fill the cache.
191 reply := (&dns.Msg{
192 MsgHdr: dns.MsgHdr{
193 Response: true,
194 },
195 Answer: []dns.RR{newRR(t, "google.com.", dns.TypeA, 3600, net.IP{8, 8, 8, 8})},
196 }).SetQuestion("google.com.", dns.TypeA)
197 reply.SetEdns0(4096, false)
198
199 // Store in cache.
200 testCache.set(request, reply, upstreamWithAddr, testLogger)
201
202 t.Run("without_do", func(t *testing.T) {
203 ci, expired, _ := testCache.get(request)
204 assert.False(t, expired)
205 assert.NotNil(t, ci)
206 })
207
208 t.Run("with_do", func(t *testing.T) {
209 reqClone := request.Copy()
210 t.Cleanup(func() {
211 request = reqClone
212 })
213
214 request.SetEdns0(4096, true)
215
216 ci, expired, _ := testCache.get(request)
217 require.Nil(t, ci)
218 assert.False(t, expired)
219 })
220}
221
222func TestCacheCNAME(t *testing.T) {
223 testCache := newTestCache(t, nil)

Callers

nothing calls this directly

Calls 4

newTestCacheFunction · 0.85
newRRFunction · 0.85
setMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…