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

Function TestCacheCNAME

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

Source from the content-addressed store, hash-verified

220}
221
222func TestCacheCNAME(t *testing.T) {
223 testCache := newTestCache(t, nil)
224
225 // Create a DNS request.
226 request := (&dns.Msg{}).SetQuestion("google.com.", dns.TypeA)
227
228 // Fill the cache
229 reply := (&dns.Msg{
230 MsgHdr: dns.MsgHdr{
231 Response: true,
232 },
233 Answer: []dns.RR{newRR(t, "google.com.", dns.TypeCNAME, 3600, "test.google.com.")},
234 }).SetQuestion("google.com.", dns.TypeA)
235 testCache.set(request, reply, upstreamWithAddr, testLogger)
236
237 t.Run("no_cnames", func(t *testing.T) {
238 r, expired, _ := testCache.get(request)
239 assert.Nil(t, r)
240 assert.False(t, expired)
241 })
242
243 // Now fill the cache with a cacheable CNAME response.
244 reply.Answer = append(reply.Answer, newRR(t, "google.com.", dns.TypeA, 3600, net.IP{8, 8, 8, 8}))
245 testCache.set(request, reply, upstreamWithAddr, testLogger)
246
247 // We are testing that a proper CNAME response gets cached
248 t.Run("cnames_exist", func(t *testing.T) {
249 r, expired, key := testCache.get(request)
250 assert.False(t, expired)
251 assert.Equal(t, key, msgToKey(request))
252
253 require.NotNil(t, r)
254
255 assert.Equal(t, testUpsAddr, r.u)
256 })
257}
258
259func TestCache_uncacheable(t *testing.T) {
260 testCache := newTestCache(t, nil)

Callers

nothing calls this directly

Calls 5

newTestCacheFunction · 0.85
newRRFunction · 0.85
msgToKeyFunction · 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…