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

all: Remove deprecated io/ioutil package usage #1090

Merged
merged 1 commit into from Nov 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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