(t *testing.T)
| 833 | } |
| 834 | |
| 835 | func TestCacheWildcardMetadata(t *testing.T) { |
| 836 | c := New() |
| 837 | qname := "foo.bar.example.org." |
| 838 | wildcard := "*.bar.example.org." |
| 839 | c.Next = wildcardMetadataBackend(qname, wildcard) |
| 840 | |
| 841 | req := new(dns.Msg) |
| 842 | req.SetQuestion(qname, dns.TypeA) |
| 843 | state := request.Request{W: &test.ResponseWriter{}, Req: req} |
| 844 | |
| 845 | // 1. Test writing wildcard metadata retrieved from backend to the cache |
| 846 | |
| 847 | ctx := metadata.ContextWithMetadata(context.TODO()) |
| 848 | w := dnstest.NewRecorder(&test.ResponseWriter{}) |
| 849 | c.ServeDNS(ctx, w, req) |
| 850 | if c.pcache.Len() != 1 { |
| 851 | t.Errorf("Msg should have been cached") |
| 852 | } |
| 853 | _, k := key(qname, w.Msg, response.NoError, state.Do(), state.Req.CheckingDisabled) |
| 854 | i, _ := c.pcache.Get(k) |
| 855 | if i.wildcard != wildcard { |
| 856 | t.Errorf("expected wildcard response to enter cache with cache item's wildcard = %q, got %q", wildcard, i.wildcard) |
| 857 | } |
| 858 | |
| 859 | // 2. Test retrieving the cached item from cache and writing its wildcard value to metadata |
| 860 | |
| 861 | // reset context and response writer |
| 862 | ctx = metadata.ContextWithMetadata(context.TODO()) |
| 863 | w = dnstest.NewRecorder(&test.ResponseWriter{}) |
| 864 | |
| 865 | c.ServeDNS(ctx, w, req) |
| 866 | f := metadata.ValueFunc(ctx, "zone/wildcard") |
| 867 | if f == nil { |
| 868 | t.Fatal("expected metadata func for wildcard response retrieved from cache, got nil") |
| 869 | } |
| 870 | if f() != wildcard { |
| 871 | t.Errorf("after retrieving wildcard item from cache, expected \"zone/wildcard\" metadata value to be %q, got %q", wildcard, i.wildcard) |
| 872 | } |
| 873 | } |
| 874 | |
| 875 | func TestCacheKeepTTL(t *testing.T) { |
| 876 | defaultTtl := 60 |
nothing calls this directly
no test coverage detected
searching dependent graphs…