Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
Multiple: "io/ioutil" has been deprecated since Go 1.16: As of Go 1.16,
the same functionality is now provided by package io or package os, and
those implementations should be preferred in new code. See the specific
function documentation for details.  (SA1019)

discovery/consul_test.go:163:11: unnecessary use of fmt.Sprintf (S1039)
  • Loading branch information
teutat3s committed Oct 25, 2022
1 parent 9b31d52 commit 8c5e115
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 26 deletions.
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/flynn/json5"
Expand Down Expand Up @@ -79,7 +79,7 @@ func RenderConfig(configFlag, renderFlag string) error {
fmt.Printf("%s", renderedConfig)
} else {
var err error
if err = ioutil.WriteFile(renderFlag, renderedConfig, 0644); err != nil {
if err = os.WriteFile(renderFlag, renderedConfig, 0644); err != nil {
return fmt.Errorf("could not write config file: %s", err)
}
}
Expand Down Expand Up @@ -108,7 +108,7 @@ func loadConfigFile(configFlag string) ([]byte, error) {
if configFlag == "" {
return nil, errors.New("-config flag is required")
}
data, err := ioutil.ReadFile(configFlag)
data, err := os.ReadFile(configFlag)
if err != nil {
return nil, fmt.Errorf("could not read config file: %s", err)
}
Expand Down
5 changes: 2 additions & 3 deletions config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package config

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -185,8 +184,8 @@ func TestRenderConfigFileStdout(t *testing.T) {
temp.Close()
os.Stdout = old

renderedOut, _ := ioutil.ReadFile(fname)
renderedFile, _ := ioutil.ReadFile("testJSON.json")
renderedOut, _ := os.ReadFile(fname)
renderedFile, _ := os.ReadFile("testJSON.json")
if string(renderedOut) != string(renderedFile) {
t.Fatalf("expected the rendered file and stdout to be identical")
}
Expand Down
3 changes: 1 addition & 2 deletions config/logger/logging_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package logger

import (
"io/ioutil"
"os"
"reflect"
"strings"
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestFileLogger(t *testing.T) {
// write a log message
logMsg := "this is a test"
logrus.Info(logMsg)
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
t.Errorf("Did not expect error: %v", err)
}
Expand Down
5 changes: 2 additions & 3 deletions control/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -56,7 +55,7 @@ func (pw PostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// process. Returns empty response or HTTP422.
func (e Endpoints) PutEnviron(r *http.Request) (interface{}, int) {
var postEnv map[string]string
jsonBlob, err := ioutil.ReadAll(r.Body)
jsonBlob, err := io.ReadAll(r.Body)
defer r.Body.Close()
if err != nil {
return nil, http.StatusUnprocessableEntity
Expand Down Expand Up @@ -110,7 +109,7 @@ func (e Endpoints) PostDisableMaintenanceMode(r *http.Request) (interface{}, int
// Returns empty response or HTTP422.
func (e Endpoints) PostMetric(r *http.Request) (interface{}, int) {
var postMetrics map[string]interface{}
jsonBlob, err := ioutil.ReadAll(r.Body)
jsonBlob, err := io.ReadAll(r.Body)

defer r.Body.Close()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions control/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package control
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestPostHandler(t *testing.T) {
ph.ServeHTTP(w, req)
resp := w.Result()
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
body, _ := io.ReadAll(resp.Body)
status := resp.StatusCode
return status, string(body)
}
Expand Down
3 changes: 1 addition & 2 deletions core/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package core

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -152,7 +151,7 @@ func TestReloadConfig(t *testing.T) {
// write the configuration to a tempfile. caller is responsible
// for calling 'defer os.Remove(f.Name())' when done
func testCfgToTempFile(t *testing.T, text string) *os.File {
f, err := ioutil.TempFile(".", "test-")
f, err := os.CreateTemp(".", "test-")
if err != nil {
t.Fatal(err)
}
Expand Down
10 changes: 5 additions & 5 deletions jobs/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package jobs

import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -167,7 +167,7 @@ func TestJobConfigConsulExtras(t *testing.T) {
}

func TestJobConfigSmokeTest(t *testing.T) {
data, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
data, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg := tests.DecodeRawToSlice(string(data))
assert := assert.New(t)

Expand Down Expand Up @@ -287,15 +287,15 @@ func TestJobConfigValidateDiscovery(t *testing.T) {
}

func TestErrJobConfigConsulEnableTagOverride(t *testing.T) {
testCfg, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
_, err := NewConfigs(tests.DecodeRawToSlice(string(testCfg)), noop)
if err == nil {
t.Errorf("ConsulExtras should have thrown error about EnableTagOverride being a string.")
}
}

func TestErrJobConfigConsulDeregisterCriticalServiceAfter(t *testing.T) {
testCfg, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
_, err := NewConfigs(tests.DecodeRawToSlice(string(testCfg)), noop)
if err == nil {
t.Errorf("error should have been generated for duration 'nope'.")
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestHealthChecksConfigError(t *testing.T) {
var noop = &mocks.NoopDiscoveryBackend{}

func loadTestConfig(t *testing.T) []*Config {
data, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
data, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg := tests.DecodeRawToSlice(string(data))

jobs, err := NewConfigs(testCfg, noop)
Expand Down
4 changes: 2 additions & 2 deletions telemetry/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package telemetry
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -270,7 +270,7 @@ func getFromTestServer(t *testing.T, testServer *httptest.Server) string {
t.Fatal(err)
} else {
defer res.Body.Close()
if resp, err := ioutil.ReadAll(res.Body); err != nil {
if resp, err := io.ReadAll(res.Body); err != nil {
t.Fatal(err)
} else {
response := string(resp)
Expand Down
4 changes: 2 additions & 2 deletions telemetry/telemetry_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package telemetry

import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -13,7 +13,7 @@ import (
)

func TestTelemetryConfigParse(t *testing.T) {
data, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
data, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg := tests.DecodeRaw(string(data))
telem, err := NewConfig(testCfg, &mocks.NoopDiscoveryBackend{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions watches/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package watches

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -11,7 +11,7 @@ import (
)

func TestWatchesParse(t *testing.T) {
data, _ := ioutil.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
data, _ := os.ReadFile(fmt.Sprintf("./testdata/%s.json5", t.Name()))
testCfg := tests.DecodeRawToSlice(string(data))
watches, err := NewConfigs(testCfg, nil)
if err != nil {
Expand Down

0 comments on commit 8c5e115

Please sign in to comment.