Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
stop using the deprecated io/ioutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
web3-bot committed Aug 25, 2022
1 parent 6ce9963 commit 21f2033
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 26 deletions.
7 changes: 3 additions & 4 deletions filewriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package files

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -20,7 +19,7 @@ func TestWriteTo(t *testing.T) {
"a": NewBytesFile([]byte("foobar")),
}),
})
tmppath, err := ioutil.TempDir("", "files-test")
tmppath, err := os.MkdirTemp("", "files-test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -60,7 +59,7 @@ func TestWriteTo(t *testing.T) {
return fmt.Errorf("expected a directory at %q", rpath)
}
} else {
actual, err := ioutil.ReadFile(cpath)
actual, err := os.ReadFile(cpath)
if err != nil {
return err
}
Expand All @@ -79,7 +78,7 @@ func TestWriteTo(t *testing.T) {
}

func TestDontAllowOverwrite(t *testing.T) {
tmppath, err := ioutil.TempDir("", "files-test")
tmppath, err := os.MkdirTemp("", "files-test")
assert.NoError(t, err)
defer os.RemoveAll(tmppath)

Expand Down
3 changes: 1 addition & 2 deletions filewriter_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package files

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -12,7 +11,7 @@ import (
)

func TestWriteToInvalidPaths(t *testing.T) {
tmppath, err := ioutil.TempDir("", "files-test")
tmppath, err := os.MkdirTemp("", "files-test")
assert.NoError(t, err)
defer os.RemoveAll(tmppath)

Expand Down
3 changes: 1 addition & 2 deletions filewriter_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package files

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -12,7 +11,7 @@ import (
)

func TestWriteToInvalidPaths(t *testing.T) {
tmppath, err := ioutil.TempDir("", "files-test")
tmppath, err := os.MkdirTemp("", "files-test")
assert.NoError(t, err)
defer os.RemoveAll(tmppath)

Expand Down
5 changes: 2 additions & 3 deletions filter_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package files

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -35,13 +34,13 @@ func TestFileFilter(t *testing.T) {
if err == nil {
t.Errorf("creating a filter without an invalid ignore file path should have failed")
}
tmppath, err := ioutil.TempDir("", "filter-test")
tmppath, err := os.MkdirTemp("", "filter-test")
if err != nil {
t.Fatal(err)
}
ignoreFilePath := filepath.Join(tmppath, "ignoreFile")
ignoreFileContents := []byte("a.txt")
if err := ioutil.WriteFile(ignoreFilePath, ignoreFileContents, 0666); err != nil {
if err := os.WriteFile(ignoreFilePath, ignoreFileContents, 0666); err != nil {
t.Fatal(err)
}
filterWithIgnoreFile, err := NewFilter(ignoreFilePath, nil, false)
Expand Down
4 changes: 2 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package files

import (
"io/ioutil"
"io"
"testing"
)

Expand Down Expand Up @@ -56,7 +56,7 @@ func CheckDir(t *testing.T, dir Directory, expected []Event) {
if !ok {
t.Fatalf("[%d] expected file to be a normal file: %T", i, it.Node())
}
out, err := ioutil.ReadAll(mf)
out, err := io.ReadAll(mf)
if err != nil {
t.Errorf("[%d] failed to read file", i)
continue
Expand Down
3 changes: 1 addition & 2 deletions multipartfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package files

import (
"io"
"io/ioutil"
"mime"
"mime/multipart"
"net/url"
Expand Down Expand Up @@ -94,7 +93,7 @@ func (w *multipartWalker) nextFile() (Node, error) {
walker: w,
}, nil
case applicationSymlink:
out, err := ioutil.ReadAll(part)
out, err := io.ReadAll(part)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions readerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package files
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
)
Expand All @@ -29,7 +28,7 @@ func NewReaderFile(reader io.Reader) File {
func NewReaderStatFile(reader io.Reader, stat os.FileInfo) File {
rc, ok := reader.(io.ReadCloser)
if !ok {
rc = ioutil.NopCloser(reader)
rc = io.NopCloser(reader)
}

return &ReaderFile{"", rc, stat, -1}
Expand Down
8 changes: 4 additions & 4 deletions serialfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package files

import (
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"sort"
Expand All @@ -22,7 +22,7 @@ func TestSerialFile(t *testing.T) {
}

func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
tmppath, err := ioutil.TempDir("", "files-test")
tmppath, err := os.MkdirTemp("", "files-test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func testSerialFile(t *testing.T, hidden, withIgnoreRules bool) {
if c == "" {
continue
}
if err := ioutil.WriteFile(path, []byte(c), 0666); err != nil {
if err := os.WriteFile(path, []byte(c), 0666); err != nil {
t.Fatal(err)
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ testInputs:
return fmt.Errorf("expected a directory at %q", path)
}
case File:
actual, err := ioutil.ReadAll(nd)
actual, err := io.ReadAll(nd)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions webfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package files

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
Expand All @@ -21,7 +21,7 @@ func TestWebFile(t *testing.T) {
t.Fatal(err)
}
wf := NewWebFile(u)
body, err := ioutil.ReadAll(wf)
body, err := io.ReadAll(wf)
if err != nil {
t.Fatal(err)
}
Expand All @@ -41,7 +41,7 @@ func TestWebFile_notFound(t *testing.T) {
t.Fatal(err)
}
wf := NewWebFile(u)
_, err = ioutil.ReadAll(wf)
_, err = io.ReadAll(wf)
if err == nil {
t.Fatal("expected error")
}
Expand All @@ -68,7 +68,7 @@ func TestWebFileSize(t *testing.T) {
t.Errorf("expected size to be %d, got %d", len(body), size)
}

actual, err := ioutil.ReadAll(wf1)
actual, err := io.ReadAll(wf1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -81,7 +81,7 @@ func TestWebFileSize(t *testing.T) {
// Read size after reading file.

wf2 := NewWebFile(u)
actual, err = ioutil.ReadAll(wf2)
actual, err = io.ReadAll(wf2)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 21f2033

Please sign in to comment.