Skip to content

Commit fa69d11

Browse files
aLekSermarkmandel
authored andcommitted
Update golangci-lint to 1.18, add bodyclose check (agones-dev#1051)
Fix some test which leaks connections.
1 parent 4bbbd24 commit fa69d11

6 files changed

Lines changed: 14 additions & 9 deletions

File tree

‎.golangci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ linters:
6060
- misspell
6161
- unparam
6262
- nakedret
63+
- bodyclose
6364

6465
issues:
6566
# This turns off the default excludes - which was causing the linter

‎build/build-image/Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RUN curl -L ${HELM_URL} > /tmp/helm.tar.gz \
6868
RUN echo "source <(helm completion bash)" >> /root/.bashrc
6969

7070
# install golang-ci linter
71-
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.16.0
71+
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $GOPATH/bin v1.18.0
7272

7373
#
7474
# \ \ / /__| |__ ___(_) |_ ___

‎pkg/util/https/https_test.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ func TestFourZeroFour(t *testing.T) {
3535
FourZeroFour(l, w, r)
3636

3737
resp := w.Result()
38+
defer resp.Body.Close() // nolint: errcheck
3839
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
3940
}

‎pkg/util/https/server_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ func TestServerRun(t *testing.T) {
5353
client := ts.server.Client()
5454
resp, err := client.Get(ts.server.URL + "/test")
5555
assert.Nil(t, err)
56+
defer resp.Body.Close() // nolint: errcheck
5657
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
5758

5859
resp, err = client.Get(ts.server.URL + "/")
5960
assert.Nil(t, err)
61+
defer resp.Body.Close() // nolint: errcheck
6062
assert.Equal(t, http.StatusOK, resp.StatusCode)
6163
}

‎pkg/util/webhooks/webhooks_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestWebHookAddHandler(t *testing.T) {
120120

121121
resp, err := client.Do(r)
122122
assert.Nil(t, err)
123+
defer resp.Body.Close() // nolint: errcheck
123124
assert.Equal(t, http.StatusOK, resp.StatusCode)
124125

125126
assert.Equal(t, handles.expected.count, callCount, "[%v] /test should have been called for %#v", k, handles)
@@ -215,6 +216,7 @@ func TestWebHookFleetValidationHandler(t *testing.T) {
215216

216217
resp, err := client.Do(r)
217218
assert.Nil(t, err)
219+
defer resp.Body.Close() // nolint: errcheck
218220
assert.Equal(t, http.StatusOK, resp.StatusCode)
219221
body, err := ioutil.ReadAll(resp.Body)
220222
assert.Nil(t, err)

‎test/e2e/allocator_test.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ func TestAllocator(t *testing.T) {
7373
}
7474

7575
// wait for the allocation system to come online
76-
var response *http.Response
7776
err = wait.PollImmediate(2*time.Second, 5*time.Minute, func() (bool, error) {
7877
// create the rest client each time, as we may end up looking at an old cert
7978
var client *http.Client
@@ -82,24 +81,24 @@ func TestAllocator(t *testing.T) {
8281
return true, err
8382
}
8483

85-
response, err = client.Post(requestURL, "application/json", bytes.NewBuffer(body))
84+
response, err := client.Post(requestURL, "application/json", bytes.NewBuffer(body))
8685
if err != nil {
8786
logrus.WithError(err).Infof("failing http request")
8887
return false, nil
8988
}
89+
defer response.Body.Close() // nolint: errcheck
90+
assert.Equal(t, http.StatusOK, response.StatusCode)
91+
body, err = ioutil.ReadAll(response.Body)
92+
if !assert.Nil(t, err) {
93+
return false, nil
94+
}
9095
return true, nil
9196
})
9297

9398
if !assert.NoError(t, err) {
9499
assert.FailNow(t, "Http test failed")
95100
}
96-
defer response.Body.Close() // nolint: errcheck
97101

98-
assert.Equal(t, http.StatusOK, response.StatusCode)
99-
body, err = ioutil.ReadAll(response.Body)
100-
if !assert.Nil(t, err) {
101-
return
102-
}
103102
result := allocationv1.GameServerAllocation{}
104103
err = json.Unmarshal(body, &result)
105104
if !assert.Nil(t, err) {

0 commit comments

Comments
 (0)