MCPcopy
hub / github.com/cortesi/devd / TestReverseProxyQuery

Function TestReverseProxyQuery

reverseproxy/reverseproxy_test.go:139–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

137}
138
139func TestReverseProxyQuery(t *testing.T) {
140 backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
141 w.Header().Set("X-Got-Query", r.URL.RawQuery)
142 w.Write([]byte("hi"))
143 }))
144 defer backend.Close()
145
146 for i, tt := range proxyQueryTests {
147 backendURL, err := url.Parse(backend.URL + tt.baseSuffix)
148 if err != nil {
149 t.Fatal(err)
150 }
151 frontend := httptest.NewServer(NewSingleHostReverseProxy(backendURL, inject.CopyInject{}))
152 req, _ := http.NewRequest("GET", frontend.URL+tt.reqSuffix, nil)
153 req.Close = true
154 res, err := http.DefaultClient.Do(req)
155 if err != nil {
156 t.Fatalf("%d. Get: %v", i, err)
157 }
158 if g, e := res.Header.Get("X-Got-Query"), tt.want; g != e {
159 t.Errorf("%d. got query %q; expected %q", i, g, e)
160 }
161 res.Body.Close()
162 frontend.Close()
163 }
164}
165
166func TestReverseProxyFlushInterval(t *testing.T) {
167 const expected = "hi"

Callers

nothing calls this directly

Calls 4

HeaderMethod · 0.80
WriteMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected