-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: replace io/ioutil with io and os package
This PR replaces the deprecated in Go 1.17 `io/ioutil` package with `io` and `os` packages. Changes are the same as in [CL 430799](https://go.dev/cl/430799) but with test fixes. Change-Id: I69095e5d62b10879fd273305876fd7498803705d GitHub-Last-Rev: 28cdff9 GitHub-Pull-Request: #17 Reviewed-on: https://go-review.googlesource.com/c/mod/+/462278 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
- Loading branch information
1 parent
77d797e
commit a42224d
Showing
7 changed files
with
64 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
"encoding/base64" | ||
"fmt" | ||
"io" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
@@ -29,7 +28,7 @@ func htop(k string, s string) string { | |
func TestHash1(t *testing.T) { | ||
files := []string{"xyz", "abc"} | ||
open := func(name string) (io.ReadCloser, error) { | ||
return ioutil.NopCloser(strings.NewReader("data for " + name)), nil | ||
return io.NopCloser(strings.NewReader("data for " + name)), nil | ||
} | ||
want := htop("h1", fmt.Sprintf("%s %s\n%s %s\n", h("data for abc"), "abc", h("data for xyz"), "xyz")) | ||
out, err := Hash1(files, open) | ||
|
@@ -47,15 +46,11 @@ func TestHash1(t *testing.T) { | |
} | ||
|
||
func TestHashDir(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "dirhash-test-") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(dir) | ||
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil { | ||
dir := t.TempDir() | ||
if err := os.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil { | ||
if err := os.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil { | ||
t.Fatal(err) | ||
} | ||
want := htop("h1", fmt.Sprintf("%s %s\n%s %s\n", h("data for abc"), "prefix/abc", h("data for xyz"), "prefix/xyz")) | ||
|
@@ -69,11 +64,10 @@ func TestHashDir(t *testing.T) { | |
} | ||
|
||
func TestHashZip(t *testing.T) { | ||
f, err := ioutil.TempFile("", "dirhash-test-") | ||
f, err := os.CreateTemp(t.TempDir(), "dirhash-test-") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(f.Name()) | ||
defer f.Close() | ||
|
||
z := zip.NewWriter(f) | ||
|
@@ -106,21 +100,17 @@ func TestHashZip(t *testing.T) { | |
|
||
func TestDirFiles(t *testing.T) { | ||
t.Run("valid directory with files", func(t *testing.T) { | ||
dir, err := ioutil.TempDir("", "dirfiles-test-") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.RemoveAll(dir) | ||
if err := ioutil.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil { | ||
dir := t.TempDir() | ||
if err := os.WriteFile(filepath.Join(dir, "xyz"), []byte("data for xyz"), 0666); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := ioutil.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil { | ||
if err := os.WriteFile(filepath.Join(dir, "abc"), []byte("data for abc"), 0666); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := os.Mkdir(filepath.Join(dir, "subdir"), 0777); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err := ioutil.WriteFile(filepath.Join(dir, "subdir", "xyz"), []byte("data for subdir xyz"), 0666); err != nil { | ||
if err := os.WriteFile(filepath.Join(dir, "subdir", "xyz"), []byte("data for subdir xyz"), 0666); err != nil { | ||
t.Fatal(err) | ||
} | ||
prefix := "foo/[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.