Skip to content

Commit

Permalink
all: Remove deprecated io/ioutil package usage (#1090)
Browse files Browse the repository at this point in the history
Previously (locally for me):

```
internal/plugintest/config.go:6:2: SA1019: "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. (staticcheck)
        "io/ioutil"
        ^
internal/plugintest/helper.go:7:2: SA1019: "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. (staticcheck)
        "io/ioutil"
        ^
internal/plugintest/working_dir.go:8:2: SA1019: "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. (staticcheck)
        "io/ioutil"
        ^
helper/logging/logging.go:6:2: SA1019: "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. (staticcheck)
        "io/ioutil"
        ^
helper/resource/plugin.go:6:2: SA1019: "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. (staticcheck)
        "io/ioutil"
        ^
```
  • Loading branch information
bflad committed Nov 4, 2022
1 parent ba4b604 commit 6275669
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
7 changes: 3 additions & 4 deletions helper/logging/logging.go
Expand Up @@ -3,7 +3,6 @@ package logging
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
Expand Down Expand Up @@ -32,7 +31,7 @@ var ValidLevels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERROR"}
// environment variable. Calls to tflog.* will have their output managed by the
// tfsdklog sink.
func LogOutput(t testing.T) (logOutput io.Writer, err error) {
logOutput = ioutil.Discard
logOutput = io.Discard

logLevel := LogLevel()
if logLevel == "" {
Expand Down Expand Up @@ -88,15 +87,15 @@ func LogOutput(t testing.T) (logOutput io.Writer, err error) {

// SetOutput checks for a log destination with LogOutput, and calls
// log.SetOutput with the result. If LogOutput returns nil, SetOutput uses
// ioutil.Discard. Any error from LogOutout is fatal.
// io.Discard. Any error from LogOutout is fatal.
func SetOutput(t testing.T) {
out, err := LogOutput(t)
if err != nil {
log.Fatal(err)
}

if out == nil {
out = ioutil.Discard
out = io.Discard
}

log.SetOutput(out)
Expand Down
8 changes: 4 additions & 4 deletions helper/resource/plugin.go
Expand Up @@ -3,7 +3,7 @@ package resource
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"strings"
"sync"
Expand Down Expand Up @@ -191,7 +191,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
Logger: hclog.New(&hclog.LoggerOptions{
Name: "plugintest",
Level: hclog.Trace,
Output: ioutil.Discard,
Output: io.Discard,
}),
NoLogOutputOverride: true,
UseTFLogSink: t,
Expand Down Expand Up @@ -279,7 +279,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
Logger: hclog.New(&hclog.LoggerOptions{
Name: "plugintest",
Level: hclog.Trace,
Output: ioutil.Discard,
Output: io.Discard,
}),
NoLogOutputOverride: true,
UseTFLogSink: t,
Expand Down Expand Up @@ -364,7 +364,7 @@ func runProviderCommand(ctx context.Context, t testing.T, f func() error, wd *pl
Logger: hclog.New(&hclog.LoggerOptions{
Name: "plugintest",
Level: hclog.Trace,
Output: ioutil.Discard,
Output: io.Discard,
}),
NoLogOutputOverride: true,
UseTFLogSink: t,
Expand Down
3 changes: 1 addition & 2 deletions internal/plugintest/config.go
Expand Up @@ -3,7 +3,6 @@ package plugintest
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -35,7 +34,7 @@ func DiscoverConfig(ctx context.Context, sourceDir string) (*Config, error) {
tfPath := os.Getenv(EnvTfAccTerraformPath)

tempDir := os.Getenv(EnvTfAccTempDir)
tfDir, err := ioutil.TempDir(tempDir, "plugintest-terraform")
tfDir, err := os.MkdirTemp(tempDir, "plugintest-terraform")
if err != nil {
return nil, fmt.Errorf("failed to create temp dir: %w", err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/plugintest/helper.go
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -70,7 +69,7 @@ func AutoInitHelper(ctx context.Context, sourceDir string) (*Helper, error) {
// automatically clean those up.
func InitHelper(ctx context.Context, config *Config) (*Helper, error) {
tempDir := os.Getenv(EnvTfAccTempDir)
baseDir, err := ioutil.TempDir(tempDir, "plugintest")
baseDir, err := os.MkdirTemp(tempDir, "plugintest")
if err != nil {
return nil, fmt.Errorf("failed to create temporary directory for test helper: %s", err)
}
Expand Down Expand Up @@ -105,7 +104,7 @@ func (h *Helper) Close() error {
// program exits, the Close method on the helper itself will attempt to
// delete it.
func (h *Helper) NewWorkingDir(ctx context.Context, t TestControl) (*WorkingDir, error) {
dir, err := ioutil.TempDir(h.baseDir, "work")
dir, err := os.MkdirTemp(h.baseDir, "work")
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/plugintest/working_dir.go
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"

Expand Down Expand Up @@ -87,7 +87,7 @@ func (wd *WorkingDir) SetConfig(ctx context.Context, cfg string) error {
if err := os.Remove(rmFilename); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("unable to remove %q: %w", rmFilename, err)
}
err := ioutil.WriteFile(outFilename, bCfg, 0700)
err := os.WriteFile(outFilename, bCfg, 0700)
if err != nil {
return err
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (wd *WorkingDir) SavedPlanRawStdout(ctx context.Context) (string, error) {
var ret bytes.Buffer

wd.tf.SetStdout(&ret)
defer wd.tf.SetStdout(ioutil.Discard)
defer wd.tf.SetStdout(io.Discard)

logging.HelperResourceTrace(ctx, "Calling Terraform CLI show command")

Expand Down

0 comments on commit 6275669

Please sign in to comment.