diff options
author | Oleksandr Redko <[email protected]> | 2023-02-19 00:43:26 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-03-01 16:28:43 +0100 |
commit | d453c12742e992d672fcf3e61b7a5ed35391c4b0 (patch) | |
tree | 1299a1f5a44bda1cf6449a8257f393350b2cc012 /watcher | |
parent | 97b010f521e592b5fc29daace225476b64543643 (diff) | |
download | hugo-d453c12742e992d672fcf3e61b7a5ed35391c4b0.tar.gz hugo-d453c12742e992d672fcf3e61b7a5ed35391c4b0.zip |
Replace deprecated ioutil with io and os
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
Diffstat (limited to 'watcher')
-rw-r--r-- | watcher/filenotify/poller_test.go | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/watcher/filenotify/poller_test.go b/watcher/filenotify/poller_test.go index b4723c758..336314fff 100644 --- a/watcher/filenotify/poller_test.go +++ b/watcher/filenotify/poller_test.go @@ -4,7 +4,6 @@ package filenotify import ( "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -35,11 +34,10 @@ func TestPollerAddRemove(t *testing.T) { c.Assert(w.Add("foo"), qt.Not(qt.IsNil)) c.Assert(w.Remove("foo"), qt.Not(qt.IsNil)) - f, err := ioutil.TempFile("", "asdf") + f, err := os.CreateTemp(t.TempDir(), "asdf") if err != nil { t.Fatal(err) } - defer os.RemoveAll(f.Name()) c.Assert(w.Add(f.Name()), qt.IsNil) c.Assert(w.Remove(f.Name()), qt.IsNil) @@ -66,7 +64,7 @@ func TestPollerEvent(t *testing.T) { filename := filepath.Join(subdir, "file1") // Write to one file. - c.Assert(ioutil.WriteFile(filename, []byte("changed"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filename, []byte("changed"), 0600), qt.IsNil) var expected []fsnotify.Event @@ -86,7 +84,7 @@ func TestPollerEvent(t *testing.T) { // Add one file. filename = filepath.Join(subdir, "file3") - c.Assert(ioutil.WriteFile(filename, []byte("new"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filename, []byte("new"), 0600), qt.IsNil) assertEvents(c, w, fsnotify.Event{Name: filename, Op: fsnotify.Create}) // Remove entire directory. @@ -127,9 +125,10 @@ func TestPollerEvent(t *testing.T) { func TestPollerClose(t *testing.T) { c := qt.New(t) w := NewPollingWatcher(watchWaitTime) - f1, err := ioutil.TempFile("", "f1") + f1, err := os.CreateTemp("", "f1") c.Assert(err, qt.IsNil) - f2, err := ioutil.TempFile("", "f2") + defer os.Remove(f1.Name()) + f2, err := os.CreateTemp("", "f2") c.Assert(err, qt.IsNil) filename1 := f1.Name() filename2 := f2.Name() @@ -140,12 +139,12 @@ func TestPollerClose(t *testing.T) { c.Assert(w.Add(filename2), qt.IsNil) c.Assert(w.Close(), qt.IsNil) c.Assert(w.Close(), qt.IsNil) - c.Assert(ioutil.WriteFile(filename1, []byte("new"), 0600), qt.IsNil) - c.Assert(ioutil.WriteFile(filename2, []byte("new"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filename1, []byte("new"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filename2, []byte("new"), 0600), qt.IsNil) // No more event as the watchers are closed. assertEvents(c, w) - f2, err = ioutil.TempFile("", "f2") + f2, err = os.CreateTemp("", "f2") c.Assert(err, qt.IsNil) defer os.Remove(f2.Name()) @@ -172,7 +171,7 @@ func TestCheckChange(t *testing.T) { c.Assert(os.Chmod(filepath.Join(filepath.Join(dir, subdir2, "file1")), 0400), qt.IsNil) f1_2 := stat(subdir2, "file1") - c.Assert(ioutil.WriteFile(filepath.Join(filepath.Join(dir, subdir2, "file2")), []byte("changed"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filepath.Join(filepath.Join(dir, subdir2, "file2")), []byte("changed"), 0600), qt.IsNil) f2_2 := stat(subdir2, "file2") c.Assert(checkChange(f0, nil), qt.Equals, fsnotify.Remove) @@ -221,17 +220,16 @@ func BenchmarkPoller(b *testing.B) { } func prepareTestDirWithSomeFiles(c *qt.C, id string) string { - dir, err := ioutil.TempDir("", fmt.Sprintf("test-poller-dir-%s", id)) - c.Assert(err, qt.IsNil) + dir := c.TB.TempDir() c.Assert(os.MkdirAll(filepath.Join(dir, subdir1), 0777), qt.IsNil) c.Assert(os.MkdirAll(filepath.Join(dir, subdir2), 0777), qt.IsNil) for i := 0; i < 3; i++ { - c.Assert(ioutil.WriteFile(filepath.Join(dir, subdir1, fmt.Sprintf("file%d", i)), []byte("hello1"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filepath.Join(dir, subdir1, fmt.Sprintf("file%d", i)), []byte("hello1"), 0600), qt.IsNil) } for i := 0; i < 3; i++ { - c.Assert(ioutil.WriteFile(filepath.Join(dir, subdir2, fmt.Sprintf("file%d", i)), []byte("hello2"), 0600), qt.IsNil) + c.Assert(os.WriteFile(filepath.Join(dir, subdir2, fmt.Sprintf("file%d", i)), []byte("hello2"), 0600), qt.IsNil) } c.Cleanup(func() { |