migrate away from deprecated ioutil APIs (#7175)

Co-authored-by: Callum Waters <cmwaters19@gmail.com>
Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
This commit is contained in:
Sharad Chand
2021-10-28 10:34:07 -07:00
committed by GitHub
co-authored by Callum Waters M. J. Fromberger
parent 6108d0a9b5
commit 8441b3715a
58 changed files with 158 additions and 192 deletions
+1 -2
View File
@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@@ -19,7 +18,7 @@ func WriteConfigVals(dir string, vals map[string]string) error {
data += fmt.Sprintf("%s = \"%s\"\n", k, v)
}
cfile := filepath.Join(dir, "config.toml")
return ioutil.WriteFile(cfile, []byte(data), 0600)
return os.WriteFile(cfile, []byte(data), 0600)
}
// RunWithArgs executes the given command with the specified command line args
+2 -2
View File
@@ -2,7 +2,7 @@ package cli
import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"testing"
@@ -55,7 +55,7 @@ func TestSetupEnv(t *testing.T) {
}
func tempDir() string {
cdir, err := ioutil.TempDir("", "test-cli")
cdir, err := os.MkdirTemp("", "test-cli")
if err != nil {
panic(err)
}
+8 -9
View File
@@ -3,7 +3,6 @@ package os_test
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -16,7 +15,7 @@ import (
)
func TestCopyFile(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
if err != nil {
t.Fatal(err)
}
@@ -33,7 +32,7 @@ func TestCopyFile(t *testing.T) {
if _, err := os.Stat(copyfile); os.IsNotExist(err) {
t.Fatal("copy should exist")
}
data, err := ioutil.ReadFile(copyfile)
data, err := os.ReadFile(copyfile)
if err != nil {
t.Fatal(err)
}
@@ -70,7 +69,7 @@ func TestTrapSignal(t *testing.T) {
}
func TestEnsureDir(t *testing.T) {
tmp, err := ioutil.TempDir("", "ensure-dir")
tmp, err := os.MkdirTemp("", "ensure-dir")
require.NoError(t, err)
defer os.RemoveAll(tmp)
@@ -84,7 +83,7 @@ func TestEnsureDir(t *testing.T) {
require.NoError(t, err)
// Should fail on file.
err = ioutil.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
err = os.WriteFile(filepath.Join(tmp, "file"), []byte{}, 0644)
require.NoError(t, err)
err = tmos.EnsureDir(filepath.Join(tmp, "file"), 0755)
require.Error(t, err)
@@ -140,7 +139,7 @@ func newTestProgram(t *testing.T, environVar string) (cmd *exec.Cmd, stdout *byt
// the origin is positively a non-directory and that it is ready for copying.
// See https://github.com/tendermint/tendermint/issues/6427
func TestTrickedTruncation(t *testing.T) {
tmpDir, err := ioutil.TempDir(os.TempDir(), "pwn_truncate")
tmpDir, err := os.MkdirTemp(os.TempDir(), "pwn_truncate")
if err != nil {
t.Fatal(err)
}
@@ -148,12 +147,12 @@ func TestTrickedTruncation(t *testing.T) {
originalWALPath := filepath.Join(tmpDir, "wal")
originalWALContent := []byte("I AM BECOME DEATH, DESTROYER OF ALL WORLDS!")
if err := ioutil.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
if err := os.WriteFile(originalWALPath, originalWALContent, 0755); err != nil {
t.Fatal(err)
}
// 1. Sanity check.
readWAL, err := ioutil.ReadFile(originalWALPath)
readWAL, err := os.ReadFile(originalWALPath)
if err != nil {
t.Fatal(err)
}
@@ -168,7 +167,7 @@ func TestTrickedTruncation(t *testing.T) {
}
// 3. Check the WAL's content
reReadWAL, err := ioutil.ReadFile(originalWALPath)
reReadWAL, err := os.ReadFile(originalWALPath)
if err != nil {
t.Fatal(err)
}