MCPcopy Create free account
hub / github.com/coder/coder / newReloadTestHarness

Function newReloadTestHarness

enterprise/aibridgeproxyd/reload_test.go:148–185  ·  view source on GitHub ↗

newReloadTestHarness boots a proxy with an empty initial router and a store-backed RefreshProviders. Production wiring is identical: the daemon constructs the proxy without preconfigured provider hosts and lets Reload populate the router from the database.

(t *testing.T)

Source from the content-addressed store, hash-verified

146// daemon constructs the proxy without preconfigured provider hosts and
147// lets Reload populate the router from the database.
148func newReloadTestHarness(t *testing.T) *reloadTestHarness {
149 t.Helper()
150
151 recorder := &aibridgedRecorder{}
152 bridged := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
153 recorder.record(r.URL.Path)
154 w.WriteHeader(http.StatusOK)
155 _, _ = w.Write([]byte("aibridged"))
156 }))
157 t.Cleanup(bridged.Close)
158
159 store := &providerStore{}
160 metrics := aibridgeproxyd.NewMetrics(prometheus.NewRegistry())
161 srv := newTestProxy(t,
162 withCoderAccessURL(bridged.URL),
163 withAllowedPorts("443"),
164 withRefreshProviders(store.refresh),
165 withMetrics(metrics),
166 )
167
168 certPool := getProxyCertPool(t)
169 client := newProxyClient(t, srv, makeProxyAuthHeader("coder-token"), certPool, false)
170 // Disable keep-alives so each request opens a fresh CONNECT through
171 // the proxy. Per the Reload contract, already-MITM'd tunnels keep
172 // the provider name they captured at CONNECT time; only new
173 // connections see the post-Reload snapshot. Tests need a fresh
174 // CONNECT between phases to assert on the new routing.
175 client.Transport.(*http.Transport).DisableKeepAlives = true
176
177 return &reloadTestHarness{
178 srv: srv,
179 store: store,
180 metrics: metrics,
181 client: client,
182 bridged: bridged,
183 recorder: recorder,
184 }
185}
186
187// requestResult is the outcome of sending a request through the proxy.
188// Either err is set (CONNECT failed for a non-MITM'd host whose dial

Calls 14

recordMethod · 0.95
NewMetricsFunction · 0.92
newTestProxyFunction · 0.85
withCoderAccessURLFunction · 0.85
withAllowedPortsFunction · 0.85
withRefreshProvidersFunction · 0.85
getProxyCertPoolFunction · 0.85
newProxyClientFunction · 0.85
withMetricsFunction · 0.70
makeProxyAuthHeaderFunction · 0.70
HelperMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected