Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: Ban the usage of ioutil package #747

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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