(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string)
| 614 | } |
| 615 | |
| 616 | func setAndGetCache(t *testing.T, c *cache, g *sync.WaitGroup, host, ip string) { |
| 617 | defer g.Done() |
| 618 | |
| 619 | ipAddr := net.ParseIP(ip) |
| 620 | |
| 621 | req := (&dns.Msg{ |
| 622 | MsgHdr: dns.MsgHdr{ |
| 623 | Id: dns.Id(), |
| 624 | }, |
| 625 | }).SetQuestion(host, dns.TypeA) |
| 626 | |
| 627 | dnsMsg := (&dns.Msg{ |
| 628 | MsgHdr: dns.MsgHdr{ |
| 629 | Response: true, |
| 630 | }, |
| 631 | Answer: []dns.RR{newRR(t, host, dns.TypeA, 1, ipAddr)}, |
| 632 | }).SetQuestion(host, dns.TypeA) |
| 633 | |
| 634 | c.set(req, dnsMsg, upstreamWithAddr, testLogger) |
| 635 | |
| 636 | for range 2 { |
| 637 | ci, expired, key := c.get(dnsMsg) |
| 638 | require.NotNilf(t, ci, "no cache found for %s", host) |
| 639 | |
| 640 | assert.False(t, expired) |
| 641 | assert.Equal(t, msgToKey(req), key) |
| 642 | |
| 643 | requireEqualMsgs(t, ci.m, dnsMsg) |
| 644 | } |
| 645 | |
| 646 | assert.Eventuallyf(t, func() bool { |
| 647 | ci, _, _ := c.get(req) |
| 648 | |
| 649 | return ci == nil |
| 650 | }, cacheTimeout, cacheTick, "cache for %s should already be removed", host) |
| 651 | } |
| 652 | |
| 653 | func TestCache_getWithSubnet(t *testing.T) { |
| 654 | const testFQDN = "example.com." |
no test coverage detected
searching dependent graphs…