Skip to content

Commit abfa458

Browse files
committed
Replace deprecated ioutil
1 parent d07b816 commit abfa458

File tree

16 files changed

+56
-60
lines changed

16 files changed

+56
-60
lines changed

api/api_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
"errors"
1212
"fmt"
1313
"io"
14-
"io/ioutil"
1514
"net/http"
1615
"net/http/httptest"
16+
"os"
1717
"path/filepath"
1818
"regexp"
1919
"testing"
@@ -355,7 +355,7 @@ func TestServeWithTLS(t *testing.T) {
355355
tlsConf := &tls.Config{}
356356
if tc.clientCACert != "" {
357357
caCertPool := x509.NewCertPool()
358-
caCert, err := ioutil.ReadFile(tc.clientCACert)
358+
caCert, err := os.ReadFile(tc.clientCACert)
359359
require.NoError(t, err)
360360
caCertPool.AppendCertsFromPEM(caCert)
361361
tlsConf = &tls.Config{
@@ -550,11 +550,11 @@ func TestServeWithMutualTLS_MultipleCA(t *testing.T) {
550550
cleanup := testutils.MakeTempDir(t, tmpDir)
551551
defer cleanup()
552552
for _, src := range caFiles {
553-
input, err := ioutil.ReadFile(src)
553+
input, err := os.ReadFile(src)
554554
file := filepath.Base(src)
555555
dest := filepath.Join(tmpDir, file)
556556
require.NoError(t, err)
557-
err = ioutil.WriteFile(dest, input, 0644)
557+
err = os.WriteFile(dest, input, 0644)
558558
require.NoError(t, err)
559559
}
560560

api/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"encoding/json"
1010
"errors"
1111
"fmt"
12-
"io/ioutil"
12+
"io"
1313
"net/http"
1414
"testing"
1515
"time"
@@ -82,7 +82,7 @@ func TestRequest(t *testing.T) {
8282
require.NoError(t, err)
8383
bytesR := bytes.NewBuffer(b)
8484
mockResp := &http.Response{
85-
Body: ioutil.NopCloser(bytesR),
85+
Body: io.NopCloser(bytesR),
8686
StatusCode: tc.httpStatus,
8787
}
8888
hc.On("Do", mock.Anything).Return(mockResp, tc.httpError).Once()

api/task.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package api
66
import (
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"sort"
1212
"strings"
@@ -101,7 +101,7 @@ func (h *taskHandler) updateTask(w http.ResponseWriter, r *http.Request) {
101101
return
102102
}
103103

104-
body, err := ioutil.ReadAll(r.Body)
104+
body, err := io.ReadAll(r.Body)
105105
if err != nil {
106106
logger.Trace("unable to read request body from update", "error", err)
107107
jsonErrorResponse(ctx, w, http.StatusInternalServerError, err)

command/commands_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
package command
55

66
import (
7-
"io/ioutil"
7+
"io"
88
"testing"
99

1010
"github.com/mitchellh/cli"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

1414
func Test_Commands(t *testing.T) {
15-
cf := Commands(ioutil.Discard, ioutil.Discard)
15+
cf := Commands(io.Discard, io.Discard)
1616

1717
// map of commands to synopsis
1818
expectedCommands := map[string]cli.Command{

command/meta.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"flag"
88
"fmt"
99
"io"
10-
"io/ioutil"
1110
"net/url"
1211
"strings"
1312

@@ -82,7 +81,7 @@ func (m *meta) defaultFlagSet(name string) *flag.FlagSet {
8281
m.tls.sslVerify = m.flags.Bool(FlagSSLVerify, true, fmt.Sprintf("Boolean to verify SSL or not. Set to true to verify SSL. "+
8382
"\n\t\tThis can also be specified using the %s environment variable.", api.EnvTLSSSLVerify))
8483

85-
m.flags.SetOutput(ioutil.Discard)
84+
m.flags.SetOutput(io.Discard)
8685

8786
return m.flags
8887
}

config/config.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package config
66
import (
77
"encoding/json"
88
"fmt"
9-
"io/ioutil"
109
"os"
1110
"path/filepath"
1211
"strconv"
@@ -489,7 +488,7 @@ func fromFile(path string) (*Config, error) {
489488
}
490489

491490
logger := logging.Global().Named(logSystemName)
492-
content, err := ioutil.ReadFile(path)
491+
content, err := os.ReadFile(path)
493492
if err != nil {
494493
logger.Error("failed reading config file from disk", filePathLogKey, path)
495494
return nil, err
@@ -533,7 +532,7 @@ func fromPath(path string) (*Config, error) {
533532
}
534533

535534
// Ensure the given filepath has at least one config file
536-
files, err := ioutil.ReadDir(path)
535+
files, err := os.ReadDir(path)
537536
if err != nil {
538537
logger.Error("failed listing directory", filePathLogKey, path)
539538
return nil, err
@@ -591,7 +590,7 @@ func stringFromEnv(list []string, def string) *string {
591590

592591
func stringFromFile(list []string, def string) *string {
593592
for _, s := range list {
594-
c, err := ioutil.ReadFile(s)
593+
c, err := os.ReadFile(s)
595594
if err == nil {
596595
return String(strings.TrimSpace(string(c)))
597596
}

driver/terraform.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
"context"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"log"
1212
"os"
1313
"path/filepath"
@@ -145,7 +145,7 @@ func NewTerraform(config *TerraformConfig) (*Terraform, error) {
145145
postApply: h,
146146
resolver: hcat.NewResolver(),
147147
watcher: config.Watcher,
148-
fileReader: ioutil.ReadFile,
148+
fileReader: os.ReadFile,
149149
logger: logger,
150150
}, nil
151151
}
@@ -496,7 +496,7 @@ func (tf *Terraform) inspectTask(ctx context.Context, returnPlan bool) (InspectP
496496
if tf.logClient {
497497
tfLogger = log.New(log.Writer(), "", log.Flags())
498498
} else {
499-
tfLogger = log.New(ioutil.Discard, "", 0)
499+
tfLogger = log.New(io.Discard, "", 0)
500500
}
501501
defer tf.client.SetStdout(tfLogger.Writer())
502502
}

e2e/command_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package e2e
99

1010
import (
1111
"fmt"
12-
"io/ioutil"
1312
"os"
1413
"path/filepath"
1514
"regexp"
@@ -631,7 +630,7 @@ task {
631630
// If required by test case, verify contents of generated variables file
632631
for _, v := range tc.tfVarsFiles {
633632
expectedFilePath := filepath.Join(tempDir, taskName, "variables.auto.tfvars")
634-
b, err := ioutil.ReadFile(expectedFilePath)
633+
b, err := os.ReadFile(expectedFilePath)
635634
require.NoError(t, err)
636635
assert.Contains(t, string(b), v)
637636
}

templates/hcltmpl/integration_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package hcltmpl
88

99
import (
1010
"context"
11-
"io/ioutil"
11+
"io"
1212
"testing"
1313
"time"
1414

@@ -77,8 +77,8 @@ func TestLoadDynamicConfig_ConsulKV(t *testing.T) {
7777
srv, err := testutil.NewTestServerConfigT(tb,
7878
func(c *testutil.TestServerConfig) {
7979
c.LogLevel = "warn"
80-
c.Stdout = ioutil.Discard
81-
c.Stderr = ioutil.Discard
80+
c.Stdout = io.Discard
81+
c.Stderr = io.Discard
8282
})
8383
require.NoError(t, err)
8484
clients := hcat.NewClientSet()

templates/tftmpl/golden_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"bytes"
88
"flag"
99
"io"
10-
"io/ioutil"
10+
"os"
1111
"testing"
1212

1313
"github.com/hashicorp/consul-terraform-sync/templates/hcltmpl"
@@ -514,7 +514,7 @@ func TestNewFiles(t *testing.T) {
514514
func checkGoldenFile(t *testing.T, goldenFile string, actual string) {
515515
// update golden files if necessary
516516
if *update {
517-
if err := ioutil.WriteFile(goldenFile, []byte(actual), 0644); err != nil {
517+
if err := os.WriteFile(goldenFile, []byte(actual), 0644); err != nil {
518518
require.NoError(t, err)
519519
}
520520
}

0 commit comments

Comments
 (0)