Skip to content

Commit 013df0b

Browse files
Alexey Panfilovclaude
andcommitted
fix(adminapi): handle http.Client.Do errors in tests to satisfy go vet
The forward-auth test used resp before checking err, which go vet flags as a likely bug. CI's Build & Vet job failed on ab0a065 because of it. Also drop the dead `_ = body` scaffold that was left over from an earlier debugging attempt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent ab0a065 commit 013df0b

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

internal/adminapi/adminapi_test.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,24 @@ func TestAuthForwardAuth(t *testing.T) {
134134
srv := httptest.NewServer(mux)
135135
defer srv.Close()
136136

137-
// With header → 200.
138-
req, _ := http.NewRequest("GET", srv.URL+"/healthz", nil)
137+
// With header → 200 on an authed route.
138+
req, _ := http.NewRequest("GET", srv.URL+"/routing", nil)
139139
req.Header.Set("X-authentik-username", "alice")
140-
// healthz is unauthenticated anyway. Hit /routing instead (authed).
141-
req.URL.Path = "/routing"
142-
resp, _ := srv.Client().Do(req)
140+
resp, err := srv.Client().Do(req)
141+
if err != nil {
142+
t.Fatalf("forward-auth req: %v", err)
143+
}
143144
defer resp.Body.Close()
144145
if resp.StatusCode != http.StatusOK {
145-
body, _ := bytes.NewBuffer(nil), resp.Body
146146
t.Errorf("expected 200 with forward-auth header, got %d", resp.StatusCode)
147-
_ = body
148147
}
149148

150149
// Without header → 401.
151150
req2, _ := http.NewRequest("GET", srv.URL+"/routing", nil)
152-
resp2, _ := srv.Client().Do(req2)
151+
resp2, err := srv.Client().Do(req2)
152+
if err != nil {
153+
t.Fatalf("no-auth req: %v", err)
154+
}
153155
defer resp2.Body.Close()
154156
if resp2.StatusCode != http.StatusUnauthorized {
155157
t.Errorf("expected 401 without forward-auth header, got %d", resp2.StatusCode)

0 commit comments

Comments
 (0)