(t *testing.T)
| 220 | } |
| 221 | |
| 222 | func 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 | |
| 259 | func TestCache_uncacheable(t *testing.T) { |
| 260 | testCache := newTestCache(t, nil) |
nothing calls this directly
no test coverage detected
searching dependent graphs…