isCachedWithCustomConfig is a helper function that returns the caching results of a constructed request using the provided custom upstream configuration and FQDN.
( tb testing.TB, p *proxy.Proxy, conf *proxy.CustomUpstreamConfig, fqdn string, )
| 38 | // results of a constructed request using the provided custom upstream |
| 39 | // configuration and FQDN. |
| 40 | func isCachedWithCustomConfig( |
| 41 | tb testing.TB, |
| 42 | p *proxy.Proxy, |
| 43 | conf *proxy.CustomUpstreamConfig, |
| 44 | fqdn string, |
| 45 | ) (isCached bool) { |
| 46 | tb.Helper() |
| 47 | |
| 48 | d := &proxy.DNSContext{ |
| 49 | CustomUpstreamConfig: conf, |
| 50 | Req: (&dns.Msg{}).SetQuestion(fqdn, dns.TypeA), |
| 51 | } |
| 52 | |
| 53 | err := p.Resolve(testutil.ContextWithTimeout(tb, defaultTimeout), d) |
| 54 | require.NoError(tb, err) |
| 55 | |
| 56 | qs := d.QueryStatistics() |
| 57 | require.NotNil(tb, qs) |
| 58 | |
| 59 | s := qs.Main() |
| 60 | require.Len(tb, s, 1) |
| 61 | |
| 62 | return s[0].IsCached |
| 63 | } |
| 64 | |
| 65 | func TestProxy_Resolve_cache(t *testing.T) { |
| 66 | const host = "example.test." |
no test coverage detected
searching dependent graphs…