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

remove io/ioutil #910

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions benchmark/bench_datasets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package benchmark_test
import (
"compress/gzip"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -74,7 +73,7 @@ func fixture(tb testing.TB, path string) []byte {
gz, err := gzip.NewReader(f)
require.NoError(tb, err)

buf, err := ioutil.ReadAll(gz)
buf, err := os.ReadAll(gz)
require.NoError(tb, err)
return buf
}
8 changes: 4 additions & 4 deletions benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package benchmark_test

import (
"bytes"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -59,7 +59,7 @@ func BenchmarkUnmarshal(b *testing.B) {
})

b.Run("ReferenceFile", func(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func BenchmarkMarshal(b *testing.B) {
})

b.Run("ReferenceFile", func(b *testing.B) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -344,7 +344,7 @@ type benchmarkDoc struct {
}

func TestUnmarshalReferenceFile(t *testing.T) {
bytes, err := ioutil.ReadFile("benchmark.toml")
bytes, err := os.ReadFile("benchmark.toml")
require.NoError(t, err)
d := benchmarkDoc{}
err = toml.Unmarshal(bytes, &d)
Expand Down
7 changes: 3 additions & 4 deletions cmd/tomltestgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"go/format"
"io"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -72,7 +71,7 @@ func downloadTmpFile(url string) string {
}
defer resp.Body.Close()

tmpfile, err := ioutil.TempFile("", "toml-test-*.zip")
tmpfile, err := os.CreateTemp("", "toml-test-*.zip")
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -113,7 +112,7 @@ func readFileFromZip(f *zip.File) string {
panic(err)
}
defer reader.Close()
bytes, err := ioutil.ReadAll(reader)
bytes, err := io.ReadAll(reader)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -216,7 +215,7 @@ func main() {
return
}

err = os.WriteFile(*out, outputBytes, 0644)
err = os.WriteFile(*out, outputBytes, 0o644)
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletions fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package toml_test

import (
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -13,7 +13,7 @@ import (
)

func FuzzUnmarshal(f *testing.F) {
file, err := ioutil.ReadFile("benchmark/benchmark.toml")
file, err := os.ReadFile("benchmark/benchmark.toml")
if err != nil {
panic(err)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"

"github.com/pelletier/go-toml/v2"
Expand Down Expand Up @@ -72,7 +71,7 @@ func (p *Program) runAllFilesInPlace(files []string) error {
}

func (p *Program) runFileInPlace(path string) error {
in, err := ioutil.ReadFile(path)
in, err := os.ReadFile(path)
if err != nil {
return err
}
Expand All @@ -84,5 +83,5 @@ func (p *Program) runFileInPlace(path string) error {
return err
}

return ioutil.WriteFile(path, out.Bytes(), 0600)
return os.WriteFile(path, out.Bytes(), 0o600)
}
21 changes: 10 additions & 11 deletions internal/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -64,7 +63,7 @@ func TestProcessMainStdinDecodeErr(t *testing.T) {
}

func TestProcessMainFileExists(t *testing.T) {
tmpfile, err := ioutil.TempFile("", "example")
tmpfile, err := os.CreateTemp("", "example")
require.NoError(t, err)
defer os.Remove(tmpfile.Name())
_, err = tmpfile.Write([]byte(`some data`))
Expand Down Expand Up @@ -96,16 +95,16 @@ func TestProcessMainFileDoesNotExist(t *testing.T) {
}

func TestProcessMainFilesInPlace(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dir)

path1 := path.Join(dir, "file1")
path2 := path.Join(dir, "file2")

err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
err = os.WriteFile(path1, []byte("content 1"), 0o600)
require.NoError(t, err)
err = ioutil.WriteFile(path2, []byte("content 2"), 0600)
err = os.WriteFile(path2, []byte("content 2"), 0o600)
require.NoError(t, err)

p := Program{
Expand All @@ -117,11 +116,11 @@ func TestProcessMainFilesInPlace(t *testing.T) {

require.Equal(t, 0, exit)

v1, err := ioutil.ReadFile(path1)
v1, err := os.ReadFile(path1)
require.NoError(t, err)
require.Equal(t, "1", string(v1))

v2, err := ioutil.ReadFile(path2)
v2, err := os.ReadFile(path2)
require.NoError(t, err)
require.Equal(t, "2", string(v2))
}
Expand All @@ -138,13 +137,13 @@ func TestProcessMainFilesInPlaceErrRead(t *testing.T) {
}

func TestProcessMainFilesInPlaceFailFn(t *testing.T) {
dir, err := ioutil.TempDir("", "")
dir, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dir)

path1 := path.Join(dir, "file1")

err = ioutil.WriteFile(path1, []byte("content 1"), 0600)
err = os.WriteFile(path1, []byte("content 1"), 0o600)
require.NoError(t, err)

p := Program{
Expand All @@ -156,13 +155,13 @@ func TestProcessMainFilesInPlaceFailFn(t *testing.T) {

require.Equal(t, -1, exit)

v1, err := ioutil.ReadFile(path1)
v1, err := os.ReadFile(path1)
require.NoError(t, err)
require.Equal(t, "content 1", string(v1))
}

func dummyFileFn(r io.Reader, w io.Writer) error {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
Loading