chore: remove refs to deprecated io/ioutil

This commit is contained in:
guoguangwu
2023-06-26 14:39:28 +08:00
parent 4b2d07e4c0
commit a84e257645
12 changed files with 20 additions and 45 deletions

View File

@@ -17,7 +17,6 @@ package enginetest
import (
"bufio"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
@@ -39,12 +38,7 @@ func TestGenNewFormatQueryPlans(t *testing.T) {
engine, err := harness.NewEngine(t)
require.NoError(t, err)
tmp, err := ioutil.TempDir("", "*")
if err != nil {
return
}
outputPath := filepath.Join(tmp, "queryPlans.txt")
outputPath := filepath.Join(t.TempDir(), "queryPlans.txt")
f, err := os.Create(outputPath)
require.NoError(t, err)

View File

@@ -16,7 +16,6 @@ package mysql_file_handler
import (
"errors"
"io/ioutil"
"os"
"sync"
@@ -53,7 +52,7 @@ func (p *Persister) Persist(ctx *sql.Context, data []byte) error {
}
}
return ioutil.WriteFile(p.privsFilePath, data, 0777)
return os.WriteFile(p.privsFilePath, data, 0777)
}
// LoadData reads the mysql.db file, returns nil if empty or not found
@@ -67,7 +66,7 @@ func (p Persister) LoadData() ([]byte, error) {
defer p.fileMutex.Unlock()
// read from mysqldbFilePath, error if something other than not-exists
buf, err := ioutil.ReadFile(p.privsFilePath)
buf, err := os.ReadFile(p.privsFilePath)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, err
}

View File

@@ -17,8 +17,7 @@ package parquet
import (
"context"
"fmt"
"io/ioutil"
"os"
"path"
"testing"
"github.com/dolthub/go-mysql-server/sql"
@@ -83,12 +82,7 @@ John Johnson,21,
Andy Anderson,27,
`
file, err := ioutil.TempFile("", "parquet")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
path := file.Name()
path := path.Join(t.TempDir(), "parquet")
rows := getSampleRows()

View File

@@ -17,7 +17,7 @@ package jwtauth
import (
"errors"
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"sync"
@@ -89,7 +89,7 @@ func (f *fetchedJWKS) GetJWKS() (*jose.JSONWebKeySet, error) {
return nil, errors.New("FetchedJWKS: Non-2xx status code from JWKS fetch")
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
contents, err := io.ReadAll(response.Body)
if err != nil {
return nil, err
}
@@ -229,7 +229,7 @@ func (t *MultiJWKS) fetch(i int) error {
if response.StatusCode/100 != 2 {
return fmt.Errorf("http request failed: StatusCode: %d", response.StatusCode)
}
contents, err := ioutil.ReadAll(response.Body)
contents, err := io.ReadAll(response.Body)
if err != nil {
return err
}

View File

@@ -18,7 +18,7 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"math/rand"
"strconv"
"strings"
@@ -129,7 +129,7 @@ func setupBenchmark(t *testing.B, dEnv *env.DoltEnv) (*sql.Context, *engine.SqlE
}
func readTestData(file string) string {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
panic(err)
}

View File

@@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"runtime"
@@ -448,7 +447,7 @@ func GetTests(config *Config, serverConfig *ServerConfig, testIdFunc func() stri
// FromFileConfig returns a validated Config based on the config file at the configPath
func FromFileConfig(configPath string) (*Config, error) {
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, err
}

View File

@@ -16,7 +16,6 @@ package sysbench_runner
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -26,9 +25,8 @@ import (
)
func TestWriteReadResultsCsv(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "TestWriteResultsCsv")
require.NoError(t, err)
err = os.MkdirAll(tmpDir, os.ModePerm)
tmpDir := t.TempDir()
err := os.MkdirAll(tmpDir, os.ModePerm)
require.NoError(t, err)
expectedOne := genRandomResult()

View File

@@ -17,7 +17,6 @@ package sysbench_runner
import (
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
)
@@ -72,7 +71,7 @@ func ReadResultsJson(filename string) (Results, error) {
var textInput io.Reader = file
b, err := ioutil.ReadAll(textInput)
b, err := io.ReadAll(textInput)
if err != nil {
return nil, err
}

View File

@@ -16,7 +16,6 @@ package sysbench_runner
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -26,8 +25,7 @@ import (
)
func TestWriteReadResultsJson(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "TestWriteResultsJson")
require.NoError(t, err)
tmpDir := t.TempDir()
defer os.RemoveAll(tmpDir)
expected := &Result{
@@ -36,7 +34,7 @@ func TestWriteReadResultsJson(t *testing.T) {
}
filename := filepath.Join(tmpDir, fmt.Sprintf("test-results%s", JsonExt))
err = WriteResultsJson(filename, []*Result{expected})
err := WriteResultsJson(filename, []*Result{expected})
require.NoError(t, err)
actual, err := ReadResultsJson(filename)

View File

@@ -15,7 +15,6 @@
package sysbench_runner
import (
"io/ioutil"
"log"
"os"
"testing"
@@ -23,12 +22,9 @@ import (
func TestRunner(t *testing.T) {
t.Skip()
dir, err := ioutil.TempDir("", "prefix")
if err != nil {
log.Fatal(err)
}
dir := t.TempDir()
log.Println(dir)
err = os.Chdir(dir)
err := os.Chdir(dir)
if err != nil {
log.Fatal(err)
}

View File

@@ -18,7 +18,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -132,7 +131,7 @@ func (c *TpccBenchmarkConfig) validateServerConfigs() error {
// FromFileConfig returns a validated Config based on the config file at the configPath
func FromFileConfig(configPath string) (*TpccBenchmarkConfig, error) {
data, err := ioutil.ReadFile(configPath)
data, err := os.ReadFile(configPath)
if err != nil {
return nil, err
}

View File

@@ -21,7 +21,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"os/signal"
@@ -167,7 +166,7 @@ func main() {
}
// Get a list of all files in this directory which end in ".bats"
files, err := ioutil.ReadDir(cwd)
files, err := os.ReadDir(cwd)
if err != nil {
cli.Println("Error reading directory:", err)
os.Exit(1)