TestForwardUncachedLogsSuccess locks in the invariant that a successful PUT/POST through the forward-proxy path produces a log line. Pre-PR this path was completely silent, leaving operators with no proxy-side breadcrumb to correlate against a downstream client error.
(t *testing.T)
| 910 | proxy.HandlePeerGet(rec, req) |
| 911 | |
| 912 | if rec.Code != http.StatusOK { |
| 913 | t.Fatalf("HandlePeerGet status = %d, want 200", rec.Code) |
| 914 | } |
| 915 | if rec.Body.String() != string(body) { |
| 916 | t.Fatalf("HandlePeerGet body = %q, want %q", rec.Body.String(), body) |
| 917 | } |
| 918 | if hitsAfter := counterValue(t, cacheHitsTotal); hitsAfter != hitsBefore { |
| 919 | t.Fatalf("cacheHitsTotal changed from %v to %v for peer traffic; only worker-facing local hits should count", hitsBefore, hitsAfter) |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | func TestHandlePeerRejectsInvalidKey(t *testing.T) { |
| 924 | proxy := newTestProxy(t) |
| 925 | for _, key := range []string{"", "../../etc/passwd", "deadbeef"} { |
| 926 | req := httptest.NewRequest("GET", "/cache/has?key="+key, nil) |
| 927 | rec := httptest.NewRecorder() |
| 928 | proxy.HandlePeerHas(rec, req) |
| 929 | if rec.Code != http.StatusBadRequest { |
| 930 | t.Errorf("HandlePeerHas(%q): status = %d, want 400", key, rec.Code) |
| 931 | } |
| 932 | req = httptest.NewRequest("GET", "/cache/get?key="+key, nil) |
| 933 | rec = httptest.NewRecorder() |
| 934 | proxy.HandlePeerGet(rec, req) |
| 935 | if rec.Code != http.StatusBadRequest { |
| 936 | t.Errorf("HandlePeerGet(%q): status = %d, want 400", key, rec.Code) |
| 937 | } |
| 938 | } |
| 939 | } |
nothing calls this directly
no test coverage detected