Skip to content

Commit 7f9513f

Browse files
committed
fix tests/lint errors
1 parent 95f2193 commit 7f9513f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

httpx/httpx_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ func TestClient_DoJSON_Success(t *testing.T) {
1616
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1717
response := map[string]string{"message": "success"}
1818
w.Header().Set("Content-Type", "application/json")
19-
json.NewEncoder(w).Encode(response)
19+
if err := json.NewEncoder(w).Encode(response); err != nil {
20+
http.Error(w, err.Error(), http.StatusInternalServerError)
21+
}
2022
}))
2123
defer server.Close()
2224

@@ -44,7 +46,9 @@ func TestClient_DoJSON_Retry(t *testing.T) {
4446
return
4547
}
4648
response := map[string]string{"message": "success"}
47-
json.NewEncoder(w).Encode(response)
49+
if err := json.NewEncoder(w).Encode(response); err != nil {
50+
http.Error(w, err.Error(), http.StatusInternalServerError)
51+
}
4852
}))
4953
defer server.Close()
5054

@@ -66,7 +70,9 @@ func TestClient_DoJSON_Retry(t *testing.T) {
6670
func TestClient_DoJSON_ContextCancellation(t *testing.T) {
6771
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6872
time.Sleep(200 * time.Millisecond)
69-
json.NewEncoder(w).Encode(map[string]string{"message": "success"})
73+
if err := json.NewEncoder(w).Encode(map[string]string{"message": "success"}); err != nil {
74+
http.Error(w, err.Error(), http.StatusInternalServerError)
75+
}
7076
}))
7177
defer server.Close()
7278

@@ -91,7 +97,9 @@ func BenchmarkClient_DoJSON(b *testing.B) {
9197
"extract": "This is a test extract with some content.",
9298
"url": "https://example.com",
9399
}
94-
json.NewEncoder(w).Encode(response)
100+
if err := json.NewEncoder(w).Encode(response); err != nil {
101+
http.Error(w, err.Error(), http.StatusInternalServerError)
102+
}
95103
}))
96104
defer server.Close()
97105

0 commit comments

Comments
 (0)