From f7c0f130cf07d7777c98e72c7379983b77bedcc8 Mon Sep 17 00:00:00 2001 From: Shahzad Lone Date: Thu, 18 Aug 2022 00:00:50 -0400 Subject: [PATCH] tools: Ban the usage of `ioutil` package (#747) - Resolves #746 We did remove all usage of `ioutil` in: https://github.com/sourcenetwork/defradb/pull/376 However, over time it has crept back in a few times, this PR will enforce that it stays banned through the linter. --- api/http/handler_test.go | 4 ++-- config/config_test.go | 13 ++++++++----- tools/configs/golangci.yaml | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/api/http/handler_test.go b/api/http/handler_test.go index 6758d1f340..1a2db7409e 100644 --- a/api/http/handler_test.go +++ b/api/http/handler_test.go @@ -13,7 +13,7 @@ package http import ( "bytes" "context" - "io/ioutil" + "io" "math" "net/http" "net/http/httptest" @@ -141,7 +141,7 @@ func TestSendJSONWithNoErrors(t *testing.T) { sendJSON(context.Background(), rec, obj, 200) - body, err := ioutil.ReadAll(rec.Result().Body) + body, err := io.ReadAll(rec.Result().Body) if err != nil { t.Fatal(err) } diff --git a/config/config_test.go b/config/config_test.go index fe5bfbb659..98aaee8bec 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -12,7 +12,6 @@ package config import ( "encoding/json" - "io/ioutil" "os" "path/filepath" "testing" @@ -183,11 +182,16 @@ func TestLoadNonExistingConfigFile(t *testing.T) { func TestLoadInvalidConfigFile(t *testing.T) { cfg := DefaultConfig() dir := t.TempDir() - ioutil.WriteFile(filepath.Join(dir, DefaultDefraDBConfigFileName), []byte("{"), 0644) - err := cfg.Load(dir) + errWrite := os.WriteFile( + filepath.Join(dir, DefaultDefraDBConfigFileName), + []byte("{"), + 0644, + ) + assert.NoError(t, errWrite) - assert.Error(t, err) + errLoad := cfg.Load(dir) + assert.Error(t, errLoad) } func TestInvalidEnvVars(t *testing.T) { @@ -242,7 +246,6 @@ func TestValidRPCTimeoutDuration(t *testing.T) { _, err := cfg.Net.RPCTimeoutDuration() assert.NoError(t, err) - assert.NoError(t, err) } func TestInvalidRPCTimeoutDuration(t *testing.T) { diff --git a/tools/configs/golangci.yaml b/tools/configs/golangci.yaml index 60fbec705c..e151cc5e1c 100644 --- a/tools/configs/golangci.yaml +++ b/tools/configs/golangci.yaml @@ -214,6 +214,8 @@ linters-settings: # Forbid the following identifiers (identifiers are written using regexp): forbid: - 'fmt\.Print.*' + - 'ioutil\.*' + # Exclude godoc examples from forbidigo checks. exclude_godoc_examples: false