Skip to content

Commit

Permalink
Replace deprecated ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmorgan committed Jun 11, 2024
1 parent df5f557 commit 67f80c4
Show file tree
Hide file tree
Showing 17 changed files with 62 additions and 67 deletions.
8 changes: 4 additions & 4 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"regexp"
"testing"
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestServeWithTLS(t *testing.T) {
tlsConf := &tls.Config{}
if tc.clientCACert != "" {
caCertPool := x509.NewCertPool()
caCert, err := ioutil.ReadFile(tc.clientCACert)
caCert, err := os.ReadFile(tc.clientCACert)
require.NoError(t, err)
caCertPool.AppendCertsFromPEM(caCert)
tlsConf = &tls.Config{
Expand Down Expand Up @@ -549,11 +549,11 @@ func TestServeWithMutualTLS_MultipleCA(t *testing.T) {
cleanup := testutils.MakeTempDir(t, tmpDir)
defer cleanup()
for _, src := range caFiles {
input, err := ioutil.ReadFile(src)
input, err := os.ReadFile(src)
file := filepath.Base(src)
dest := filepath.Join(tmpDir, file)
require.NoError(t, err)
err = ioutil.WriteFile(dest, input, 0644)
err = os.WriteFile(dest, input, 0644)
require.NoError(t, err)
}

Expand Down
13 changes: 6 additions & 7 deletions api/oapigen/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"testing"
"time"
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestRequest(t *testing.T) {
require.NoError(t, err)
bytesR := bytes.NewBuffer(b)
mockResp := &http.Response{
Body: ioutil.NopCloser(bytesR),
Body: io.NopCloser(bytesR),
StatusCode: tc.httpStatus,
}
hc.On("Do", mock.Anything).Return(mockResp, tc.httpError).Once()
Expand Down
4 changes: 2 additions & 2 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package api
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"sort"
"strings"
Expand Down Expand Up @@ -101,7 +101,7 @@ func (h *taskHandler) updateTask(w http.ResponseWriter, r *http.Request) {
return
}

body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
if err != nil {
logger.Trace("unable to read request body from update", "error", err)
jsonErrorResponse(ctx, w, http.StatusInternalServerError, err)
Expand Down
4 changes: 2 additions & 2 deletions command/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
package command

import (
"io/ioutil"
"io"
"testing"

"github.com/mitchellh/cli"
"github.com/stretchr/testify/assert"
)

func Test_Commands(t *testing.T) {
cf := Commands(ioutil.Discard, ioutil.Discard)
cf := Commands(io.Discard, io.Discard)

// map of commands to synopsis
expectedCommands := map[string]cli.Command{
Expand Down
3 changes: 1 addition & 2 deletions command/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"net/url"
"strings"

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

m.flags.SetOutput(ioutil.Discard)
m.flags.SetOutput(io.Discard)

return m.flags
}
Expand Down
7 changes: 3 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -489,7 +488,7 @@ func fromFile(path string) (*Config, error) {
}

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

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

func stringFromFile(list []string, def string) *string {
for _, s := range list {
c, err := ioutil.ReadFile(s)
c, err := os.ReadFile(s)
if err == nil {
return String(strings.TrimSpace(string(c)))
}
Expand Down
6 changes: 3 additions & 3 deletions driver/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -145,7 +145,7 @@ func NewTerraform(config *TerraformConfig) (*Terraform, error) {
postApply: h,
resolver: hcat.NewResolver(),
watcher: config.Watcher,
fileReader: ioutil.ReadFile,
fileReader: os.ReadFile,
logger: logger,
}, nil
}
Expand Down Expand Up @@ -496,7 +496,7 @@ func (tf *Terraform) inspectTask(ctx context.Context, returnPlan bool) (InspectP
if tf.logClient {
tfLogger = log.New(log.Writer(), "", log.Flags())
} else {
tfLogger = log.New(ioutil.Discard, "", 0)
tfLogger = log.New(io.Discard, "", 0)
}
defer tf.client.SetStdout(tfLogger.Writer())
}
Expand Down
3 changes: 1 addition & 2 deletions e2e/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package e2e

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -631,7 +630,7 @@ task {
// If required by test case, verify contents of generated variables file
for _, v := range tc.tfVarsFiles {
expectedFilePath := filepath.Join(tempDir, taskName, "variables.auto.tfvars")
b, err := ioutil.ReadFile(expectedFilePath)
b, err := os.ReadFile(expectedFilePath)
require.NoError(t, err)
assert.Contains(t, string(b), v)
}
Expand Down
6 changes: 3 additions & 3 deletions templates/hcltmpl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package hcltmpl

import (
"context"
"io/ioutil"
"io"
"testing"
"time"

Expand Down Expand Up @@ -77,8 +77,8 @@ func TestLoadDynamicConfig_ConsulKV(t *testing.T) {
srv, err := testutil.NewTestServerConfigT(tb,
func(c *testutil.TestServerConfig) {
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
})
require.NoError(t, err)
clients := hcat.NewClientSet()
Expand Down
4 changes: 2 additions & 2 deletions templates/tftmpl/golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"bytes"
"flag"
"io"
"io/ioutil"
"os"
"testing"

"github.com/hashicorp/consul-terraform-sync/templates/hcltmpl"
Expand Down Expand Up @@ -514,7 +514,7 @@ func TestNewFiles(t *testing.T) {
func checkGoldenFile(t *testing.T, goldenFile string, actual string) {
// update golden files if necessary
if *update {
if err := ioutil.WriteFile(goldenFile, []byte(actual), 0644); err != nil {
if err := os.WriteFile(goldenFile, []byte(actual), 0644); err != nil {
require.NoError(t, err)
}
}
Expand Down
14 changes: 7 additions & 7 deletions templates/tftmpl/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package tftmpl

import (
"context"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand All @@ -27,7 +27,7 @@ import (
)

func TestInitRootModule(t *testing.T) {
dir, err := ioutil.TempDir(".", "consul-terraform-sync-tftmpl-")
dir, err := os.MkdirTemp(".", "consul-terraform-sync-tftmpl-")
require.NoError(t, err)
defer os.RemoveAll(dir)

Expand Down Expand Up @@ -233,12 +233,12 @@ func TestRenderTFVarsTmpl(t *testing.T) {
t.Parallel()

// Setup Consul server
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
srv, err := testutil.NewTestServerConfigT(tb,
func(c *testutil.TestServerConfig) {
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard

// Hardcode node info so it doesn't change per run
c.NodeName = "worker-01"
Expand Down Expand Up @@ -275,8 +275,8 @@ func TestRenderTFVarsTmpl(t *testing.T) {
func(c *testutil.TestServerConfig) {
c.Bootstrap = false
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard

// Hardcode node info so it doesn't change per run
c.NodeName = "worker-02"
Expand Down
10 changes: 5 additions & 5 deletions templates/tftmpl/tmplfunc/catalog_services_registration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package tmplfunc

import (
"io/ioutil"
"io"
"regexp"
"testing"
"time"
Expand Down Expand Up @@ -182,8 +182,8 @@ func TestCatalogServicesRegistrationQuery_Fetch(t *testing.T) {
func(c *testutil.TestServerConfig) {
c.Bootstrap = false
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
c.NodeMeta = map[string]string{"k": "v"}
})

Expand All @@ -195,8 +195,8 @@ func TestCatalogServicesRegistrationQuery_Fetch(t *testing.T) {
c.Datacenter = "dc2"
c.Bootstrap = true
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
})
require.NoError(t, err, "failed to start consul server 3")
defer srv3.Stop()
Expand Down
10 changes: 5 additions & 5 deletions templates/tftmpl/tmplfunc/services_regex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package tmplfunc

import (
"fmt"
"io/ioutil"
"io"
"regexp"
"sort"
"testing"
Expand Down Expand Up @@ -155,8 +155,8 @@ func TestServicesRegexQuery_Fetch(t *testing.T) {
func(c *testutil.TestServerConfig) {
c.Bootstrap = false
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
c.NodeMeta = nodeMeta
})
consulSrv2 := &dep.HealthService{
Expand All @@ -175,8 +175,8 @@ func TestServicesRegexQuery_Fetch(t *testing.T) {
c.Datacenter = "dc2"
c.Bootstrap = true
c.LogLevel = "warn"
c.Stdout = ioutil.Discard
c.Stderr = ioutil.Discard
c.Stdout = io.Discard
c.Stderr = io.Discard
})
require.NoError(t, err, "failed to start consul server 3")
defer srv3.Stop()
Expand Down
Loading

0 comments on commit 67f80c4

Please sign in to comment.