Skip to content

Commit 6c138dd

Browse files
authored
Merge pull request #1524 from saschagrunert/bodyclose
Fix `bodyclose` linter
2 parents 0e15add + ea2beb9 commit 6c138dd

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ linters:
88
- asasalint
99
- asciicheck
1010
- bidichk
11+
- bodyclose
1112
- canonicalheader
1213
- containedctx
1314
- contextcheck
@@ -74,7 +75,6 @@ linters:
7475
- wastedassign
7576
- whitespace
7677
- zerologlint
77-
# - bodyclose
7878
# - cyclop
7979
# - depguard
8080
# - err113

pkg/validate/networking.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ func createHostNetWebServerContainer(rc internalapi.RuntimeService, ic internala
240240
// checkMainPage check if the we can get the main page of the pod via given IP:port.
241241
func checkMainPage(c internalapi.RuntimeService, podID string, hostPort, containerPort int32) {
242242
By("get the IP:port needed to be checked")
243-
var err error
244-
var resp *http.Response
245243

246244
url := "http://"
247245
if hostPort != 0 {
@@ -256,11 +254,28 @@ func checkMainPage(c internalapi.RuntimeService, podID string, hostPort, contain
256254

257255
By("check the content of " + url)
258256

257+
respChan := make(chan *http.Response, 1)
258+
defer close(respChan)
259+
259260
Eventually(func() error {
260-
resp, err = http.Get(url)
261-
return err
261+
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
262+
defer cancel()
263+
264+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
265+
if err != nil {
266+
return err
267+
}
268+
269+
resp, err := http.DefaultClient.Do(req)
270+
if err != nil {
271+
return err
272+
}
273+
defer resp.Body.Close()
274+
respChan <- resp
275+
return nil
262276
}, time.Minute, time.Second).Should(BeNil())
263277

278+
resp := <-respChan
264279
Expect(resp.StatusCode).To(Equal(200), "The status code of response should be 200.")
265280
framework.Logf("check port mapping succeed")
266281
}

0 commit comments

Comments
 (0)