From 9908c84b2af205047b7c2d51c1c725a8e7f339a5 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 4 May 2023 11:14:53 -0500 Subject: [PATCH] test: Return early and avoid using nil handler (#7411) * test: Return early and avoid using nil handler --- enterprise/coderd/coderdenttest/proxytest.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/enterprise/coderd/coderdenttest/proxytest.go b/enterprise/coderd/coderdenttest/proxytest.go index 6b517a5994..86b2538f7a 100644 --- a/enterprise/coderd/coderdenttest/proxytest.go +++ b/enterprise/coderd/coderdenttest/proxytest.go @@ -47,7 +47,9 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie options = &ProxyOptions{} } - // HTTP Server + // HTTP Server. We have to start this once to get the access URL to start + // the workspace proxy with. The workspace proxy has the handler, so the + // http server will start with a 503 until the proxy is started. var mutex sync.RWMutex var handler http.Handler srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { @@ -55,6 +57,7 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie defer mutex.RUnlock() if handler == nil { http.Error(w, "handler not set", http.StatusServiceUnavailable) + return } handler.ServeHTTP(w, r)