From 4c1042132bb3fa0becb4473c4f6bcf8abfc8d177 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Thu, 5 Dec 2024 20:11:49 +0100 Subject: [PATCH] Enable linter bodyclose (#1968) ## Changes Enable linter '[bodyclose](https://github.com/timakin/bodyclose)' and fix 2 cases in tests. ## Tests Existing tests. --- .golangci.yaml | 1 + libs/auth/oauth_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 28227006a..82e4d9848 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,6 +1,7 @@ linters: disable-all: true enable: + - bodyclose # errcheck and govet are part of default setup and should be included but give too many errors now # once errors are fixed, they should be enabled here: #- errcheck diff --git a/libs/auth/oauth_test.go b/libs/auth/oauth_test.go index fdf0d04bf..837ff4fee 100644 --- a/libs/auth/oauth_test.go +++ b/libs/auth/oauth_test.go @@ -15,6 +15,7 @@ import ( "github.com/databricks/databricks-sdk-go/httpclient/fixtures" "github.com/databricks/databricks-sdk-go/qa" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/oauth2" ) @@ -182,7 +183,8 @@ func TestChallenge(t *testing.T) { state := <-browserOpened resp, err := http.Get(fmt.Sprintf("http://%s?code=__THIS__&state=%s", appRedirectAddr, state)) - assert.NoError(t, err) + require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 200, resp.StatusCode) err = <-errc @@ -221,7 +223,8 @@ func TestChallengeFailed(t *testing.T) { resp, err := http.Get(fmt.Sprintf( "http://%s?error=access_denied&error_description=Policy%%20evaluation%%20failed%%20for%%20this%%20request", appRedirectAddr)) - assert.NoError(t, err) + require.NoError(t, err) + defer resp.Body.Close() assert.Equal(t, 400, resp.StatusCode) err = <-errc