Skip to content

test: Return early and avoid using nil handler #7411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: Return early and avoid using nil handler
  • Loading branch information
Emyrk committed May 4, 2023
commit cc2e708d6b17d105872c07255b89aa8041382718
5 changes: 4 additions & 1 deletion enterprise/coderd/coderdenttest/proxytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,17 @@ 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) {
mutex.RLock()
defer mutex.RUnlock()
if handler == nil {
http.Error(w, "handler not set", http.StatusServiceUnavailable)
return
}

handler.ServeHTTP(w, r)
Expand Down