From cc2e708d6b17d105872c07255b89aa8041382718 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 4 May 2023 09:13:13 -0500 Subject: [PATCH 1/2] 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 6b517a5994ca4..0146f274fdd9f 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. We need the workspace proxy to pass in the + // handler here. 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) From a6d4d60fed5d4953e30866c24ddc8fd615d78f3b Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 4 May 2023 09:14:26 -0500 Subject: [PATCH 2/2] Add comment --- enterprise/coderd/coderdenttest/proxytest.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/enterprise/coderd/coderdenttest/proxytest.go b/enterprise/coderd/coderdenttest/proxytest.go index 0146f274fdd9f..86b2538f7a673 100644 --- a/enterprise/coderd/coderdenttest/proxytest.go +++ b/enterprise/coderd/coderdenttest/proxytest.go @@ -48,8 +48,8 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie } // HTTP Server. We have to start this once to get the access URL to start - // the workspace proxy with. We need the workspace proxy to pass in the - // handler here. + // 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) {