Skip to content

Commit

Permalink
tools: Ban the usage of ioutil package (sourcenetwork#747)
Browse files Browse the repository at this point in the history
- Resolves sourcenetwork#746

We did remove all usage of `ioutil` in: sourcenetwork#376
However, over time it has crept back in a few times, this PR will enforce that it stays banned through the linter.
  • Loading branch information
shahzadlone committed Aug 18, 2022
1 parent eb721bd commit f7c0f13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/http/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ package http
import (
"bytes"
"context"
"io/ioutil"
"io"
"math"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -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)
}
Expand Down
13 changes: 8 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package config

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions tools/configs/golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f7c0f13

Please sign in to comment.