Skip to content

Commit ada5ecd

Browse files
fix: linting
1 parent 671638a commit ada5ecd

1 file changed

Lines changed: 22 additions & 22 deletions

File tree

tests/benchmarks/benchmark_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ var benchClient = &http.Client{
1515
},
1616
}
1717

18+
func drainAndCloseBody(b *testing.B, resp *http.Response) {
19+
b.Helper()
20+
21+
if _, err := io.Copy(io.Discard, resp.Body); err != nil {
22+
b.Fatalf("failed to drain response body: %v", err)
23+
}
24+
if err := resp.Body.Close(); err != nil {
25+
b.Fatalf("failed to close response body: %v", err)
26+
}
27+
}
28+
1829
func BenchmarkHealthEndpoint(b *testing.B) {
1930
b.ResetTimer()
2031
b.ReportAllocs()
@@ -27,8 +38,7 @@ func BenchmarkHealthEndpoint(b *testing.B) {
2738
if resp.StatusCode != http.StatusOK {
2839
b.Fatalf("unexpected status code: %d", resp.StatusCode)
2940
}
30-
io.Copy(io.Discard, resp.Body)
31-
resp.Body.Close()
41+
drainAndCloseBody(b, resp)
3242
}
3343
}
3444

@@ -53,8 +63,7 @@ func BenchmarkAuthGoogleInitiation(b *testing.B) {
5363
if resp.StatusCode != http.StatusTemporaryRedirect && resp.StatusCode != http.StatusFound {
5464
b.Fatalf("unexpected status code: %d", resp.StatusCode)
5565
}
56-
io.Copy(io.Discard, resp.Body)
57-
resp.Body.Close()
66+
drainAndCloseBody(b, resp)
5867
}
5968
}
6069

@@ -79,8 +88,7 @@ func BenchmarkAuthMicrosoftInitiation(b *testing.B) {
7988
if resp.StatusCode != http.StatusTemporaryRedirect && resp.StatusCode != http.StatusFound {
8089
b.Fatalf("unexpected status code: %d", resp.StatusCode)
8190
}
82-
io.Copy(io.Discard, resp.Body)
83-
resp.Body.Close()
91+
drainAndCloseBody(b, resp)
8492
}
8593
}
8694

@@ -97,8 +105,7 @@ func BenchmarkGetMe(b *testing.B) {
97105
if resp.StatusCode != http.StatusOK {
98106
b.Fatalf("unexpected status code: %d", resp.StatusCode)
99107
}
100-
io.Copy(io.Discard, resp.Body)
101-
resp.Body.Close()
108+
drainAndCloseBody(b, resp)
102109
}
103110
}
104111

@@ -115,8 +122,7 @@ func BenchmarkGetUser(b *testing.B) {
115122
if resp.StatusCode != http.StatusOK {
116123
b.Fatalf("unexpected status code: %d", resp.StatusCode)
117124
}
118-
io.Copy(io.Discard, resp.Body)
119-
resp.Body.Close()
125+
drainAndCloseBody(b, resp)
120126
}
121127
}
122128

@@ -133,8 +139,7 @@ func BenchmarkListOrganizations(b *testing.B) {
133139
if resp.StatusCode != http.StatusOK {
134140
b.Fatalf("unexpected status code: %d", resp.StatusCode)
135141
}
136-
io.Copy(io.Discard, resp.Body)
137-
resp.Body.Close()
142+
drainAndCloseBody(b, resp)
138143
}
139144
}
140145

@@ -157,8 +162,7 @@ func BenchmarkCreateOrganization(b *testing.B) {
157162
if resp.StatusCode != http.StatusCreated {
158163
b.Fatalf("unexpected status code: %d", resp.StatusCode)
159164
}
160-
io.Copy(io.Discard, resp.Body)
161-
resp.Body.Close()
165+
drainAndCloseBody(b, resp)
162166
}
163167
}
164168

@@ -175,8 +179,7 @@ func BenchmarkGetOrganization(b *testing.B) {
175179
if resp.StatusCode != http.StatusOK {
176180
b.Fatalf("unexpected status code: %d", resp.StatusCode)
177181
}
178-
io.Copy(io.Discard, resp.Body)
179-
resp.Body.Close()
182+
drainAndCloseBody(b, resp)
180183
}
181184
}
182185

@@ -193,8 +196,7 @@ func BenchmarkListEvents(b *testing.B) {
193196
if resp.StatusCode != http.StatusOK {
194197
b.Fatalf("unexpected status code: %d", resp.StatusCode)
195198
}
196-
io.Copy(io.Discard, resp.Body)
197-
resp.Body.Close()
199+
drainAndCloseBody(b, resp)
198200
}
199201
}
200202

@@ -218,8 +220,7 @@ func BenchmarkCreateEvent(b *testing.B) {
218220
if resp.StatusCode != http.StatusCreated {
219221
b.Fatalf("unexpected status code: %d", resp.StatusCode)
220222
}
221-
io.Copy(io.Discard, resp.Body)
222-
resp.Body.Close()
223+
drainAndCloseBody(b, resp)
223224
}
224225
}
225226

@@ -236,7 +237,6 @@ func BenchmarkGetEvent(b *testing.B) {
236237
if resp.StatusCode != http.StatusOK {
237238
b.Fatalf("unexpected status code: %d", resp.StatusCode)
238239
}
239-
io.Copy(io.Discard, resp.Body)
240-
resp.Body.Close()
240+
drainAndCloseBody(b, resp)
241241
}
242242
}

0 commit comments

Comments
 (0)